gecoder 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +9 -1
- data/Rakefile +3 -0
- data/example/send_most_money.rb +58 -0
- data/ext/missing.cpp +26 -1
- data/ext/missing.h +2 -0
- data/ext/vararray.cpp +31 -11
- data/ext/vararray.h +6 -0
- data/lib/gecoder/bindings.rb +5 -5
- data/lib/gecoder/bindings/bindings.rb +52 -0
- data/lib/gecoder/interface/binding_changes.rb +16 -11
- data/lib/gecoder/interface/constraints.rb +28 -15
- data/lib/gecoder/interface/constraints/bool_enum/boolean.rb +8 -17
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +8 -3
- data/lib/gecoder/interface/constraints/int/arithmetic.rb +10 -15
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +10 -16
- data/lib/gecoder/interface/constraints/int_enum/element.rb +6 -11
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +2 -1
- data/lib/gecoder/interface/constraints/set/cardinality.rb +4 -7
- data/lib/gecoder/interface/constraints/set/connection.rb +13 -22
- data/lib/gecoder/interface/model.rb +52 -41
- data/lib/gecoder/interface/search.rb +29 -24
- data/lib/gecoder/interface/variables.rb +27 -15
- data/lib/gecoder/version.rb +1 -1
- data/specs/constraints/arithmetic.rb +27 -17
- data/specs/constraints/bool_enum.rb +4 -2
- data/specs/constraints/boolean.rb +5 -2
- data/specs/constraints/cardinality.rb +28 -8
- data/specs/constraints/connection.rb +58 -37
- data/specs/constraints/constraints.rb +2 -2
- data/specs/constraints/count.rb +3 -3
- data/specs/constraints/element.rb +5 -5
- data/specs/constraints/int_domain.rb +4 -2
- data/specs/constraints/set_domain.rb +8 -4
- data/specs/constraints/set_relation.rb +10 -5
- data/specs/int_var.rb +3 -3
- data/specs/model.rb +10 -9
- data/specs/search.rb +54 -5
- data/specs/spec_helper.rb +2 -0
- data/tasks/distribution.rake +8 -1
- data/tasks/specs.rake +0 -1
- data/vendor/rust/rust/class.rb +6 -1
- data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +3 -3
- data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +15 -1
- data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +2 -0
- metadata +51 -21
| @@ -33,7 +33,7 @@ describe Gecode::Constraints::Int::CompositeStub, ' (not subclassed)' do | |
| 33 33 |  | 
| 34 34 | 
             
              it 'should raise error when calling #constrain_equal' do
         | 
| 35 35 | 
             
                lambda do 
         | 
| 36 | 
            -
                  @con.instance_eval{ constrain_equal(nil, {}) }
         | 
| 36 | 
            +
                  @con.instance_eval{ constrain_equal(nil, {}, false) }
         | 
| 37 37 | 
             
                end.should raise_error(NoMethodError)
         | 
| 38 38 | 
             
              end
         | 
| 39 39 | 
             
            end
         | 
| @@ -60,7 +60,7 @@ describe Gecode::Constraints::CompositeExpression do | |
| 60 60 | 
             
              it 'should raise error if a method doesn\'t exist' do
         | 
| 61 61 | 
             
                expression = Gecode::Constraints::CompositeExpression.new(
         | 
| 62 62 | 
             
                  Gecode::Constraints::Int::Expression, Gecode::FreeIntVar, 
         | 
| 63 | 
            -
                  Gecode::Model.new, {:lhs => nil, :negate => false}){}
         | 
| 63 | 
            +
                  lambda{ }, Gecode::Model.new, {:lhs => nil, :negate => false}){}
         | 
| 64 64 | 
             
                lambda do
         | 
| 65 65 | 
             
                  expression.this_method_does_not_exist
         | 
| 66 66 | 
             
                end.should raise_error(NoMethodError)
         | 
    
        data/specs/constraints/count.rb
    CHANGED
    
    | @@ -24,8 +24,8 @@ describe Gecode::Constraints::IntEnum::Count do | |
| 24 24 | 
             
                # Creates an expectation corresponding to the specified input.
         | 
| 25 25 | 
             
                @expect = lambda do |element, relation, target, strength, reif_var|
         | 
| 26 26 | 
             
                  @model.allow_space_access do
         | 
| 27 | 
            -
                    target =  | 
| 28 | 
            -
                    element =  | 
| 27 | 
            +
                    target = an_instance_of(Gecode::Raw::IntVar) if target.respond_to? :bind
         | 
| 28 | 
            +
                    element = an_instance_of(Gecode::Raw::IntVar) if element.respond_to? :bind
         | 
| 29 29 | 
             
                    if reif_var.nil?
         | 
| 30 30 | 
             
                      Gecode::Raw.should_receive(:count).once.with(
         | 
| 31 31 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| @@ -40,7 +40,7 @@ describe Gecode::Constraints::IntEnum::Count do | |
| 40 40 | 
             
                      Gecode::Raw.should_receive(:rel).once.with(
         | 
| 41 41 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 42 42 | 
             
                        an_instance_of(Gecode::Raw::IntVar), relation,
         | 
| 43 | 
            -
                        target,  | 
| 43 | 
            +
                        target, an_instance_of(Gecode::Raw::BoolVar), strength)
         | 
| 44 44 | 
             
                    end
         | 
| 45 45 | 
             
                  end
         | 
| 46 46 | 
             
                end
         | 
| @@ -10,9 +10,9 @@ class ElementSampleProblem < Gecode::Model | |
| 10 10 | 
             
              def initialize
         | 
| 11 11 | 
             
                prices = [17, 63, 45, 63]
         | 
| 12 12 | 
             
                @fixnum_prices = wrap_enum(prices)
         | 
| 13 | 
            -
                @prices = int_var_array(4,  | 
| 13 | 
            +
                @prices = int_var_array(4, prices)
         | 
| 14 14 | 
             
                @store = int_var(0...prices.size)
         | 
| 15 | 
            -
                @price = int_var( | 
| 15 | 
            +
                @price = int_var(prices)
         | 
| 16 16 | 
             
                branch_on wrap_enum([@store])
         | 
| 17 17 | 
             
              end
         | 
| 18 18 | 
             
            end
         | 
| @@ -28,11 +28,11 @@ describe Gecode::Constraints::IntEnum::Element do | |
| 28 28 | 
             
                # Creates an expectation corresponding to the specified input.
         | 
| 29 29 | 
             
                @expect = lambda do |element, relation, target, strength, reif_var, negated|
         | 
| 30 30 | 
             
                  @model.allow_space_access do
         | 
| 31 | 
            -
                    target =  | 
| 32 | 
            -
                    element =  | 
| 31 | 
            +
                    target = an_instance_of(Gecode::Raw::IntVar) if target.respond_to? :bind
         | 
| 32 | 
            +
                    element = an_instance_of(Gecode::Raw::IntVar) if element.respond_to? :bind
         | 
| 33 33 | 
             
                    if reif_var.nil?
         | 
| 34 34 | 
             
                      if !negated and relation == Gecode::Raw::IRT_EQ and 
         | 
| 35 | 
            -
                          target.kind_of?  | 
| 35 | 
            +
                          !target.kind_of? Fixnum
         | 
| 36 36 | 
             
                        Gecode::Raw.should_receive(:element).once.with( 
         | 
| 37 37 | 
             
                          an_instance_of(Gecode::Raw::Space), 
         | 
| 38 38 | 
             
                          an_instance_of(Gecode::Raw::IntVarArray), 
         | 
| @@ -19,11 +19,13 @@ describe Gecode::Constraints::Int::Domain do | |
| 19 19 | 
             
                    if reif_var.nil?
         | 
| 20 20 | 
             
                      Gecode::Raw.should_receive(:dom).once.with(
         | 
| 21 21 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 22 | 
            -
                         | 
| 22 | 
            +
                        an_instance_of(Gecode::Raw::IntVar), 
         | 
| 23 | 
            +
                        an_instance_of(Gecode::Raw::IntSet), strength)
         | 
| 23 24 | 
             
                    else
         | 
| 24 25 | 
             
                      Gecode::Raw.should_receive(:dom).once.with(
         | 
| 25 26 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 26 | 
            -
                         | 
| 27 | 
            +
                        an_instance_of(Gecode::Raw::IntVar), 
         | 
| 28 | 
            +
                        an_instance_of(Gecode::Raw::IntSet), 
         | 
| 27 29 | 
             
                        an_instance_of(Gecode::Raw::BoolVar), strength)
         | 
| 28 30 | 
             
                    end
         | 
| 29 31 | 
             
                  end
         | 
| @@ -18,9 +18,11 @@ describe Gecode::Constraints::Set::Domain do | |
| 18 18 | 
             
                    if reif_var.nil? and !negated
         | 
| 19 19 | 
             
                      Gecode::Raw.should_receive(:dom).once.with(
         | 
| 20 20 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 21 | 
            -
                         | 
| 21 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), relation_type, 
         | 
| 22 | 
            +
                        *expect_constant_set(rhs))
         | 
| 22 23 | 
             
                    else
         | 
| 23 | 
            -
                      params = [ | 
| 24 | 
            +
                      params = [an_instance_of(Gecode::Raw::Space), 
         | 
| 25 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), relation_type]
         | 
| 24 26 | 
             
                      params << expect_constant_set(rhs)
         | 
| 25 27 | 
             
                      params << an_instance_of(Gecode::Raw::BoolVar)
         | 
| 26 28 | 
             
                      Gecode::Raw.should_receive(:dom).once.with(*params.flatten)
         | 
| @@ -98,9 +100,11 @@ describe Gecode::Constraints::Set::Domain, ' (equality)' do | |
| 98 100 | 
             
                    if reif_var.nil?
         | 
| 99 101 | 
             
                      Gecode::Raw.should_receive(:dom).once.with(
         | 
| 100 102 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 101 | 
            -
                         | 
| 103 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), relation_type, 
         | 
| 104 | 
            +
                        *expect_constant_set(rhs))
         | 
| 102 105 | 
             
                    else
         | 
| 103 | 
            -
                      params = [ | 
| 106 | 
            +
                      params = [an_instance_of(Gecode::Raw::Space), 
         | 
| 107 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), relation_type]
         | 
| 104 108 | 
             
                      params << expect_constant_set(rhs)
         | 
| 105 109 | 
             
                      params << an_instance_of(Gecode::Raw::BoolVar)
         | 
| 106 110 | 
             
                      Gecode::Raw.should_receive(:dom).once.with(*params.flatten)
         | 
| @@ -14,11 +14,13 @@ describe Gecode::Constraints::Set::Relation do | |
| 14 14 | 
             
                    if reif_var.nil? and !negated
         | 
| 15 15 | 
             
                      Gecode::Raw.should_receive(:rel).once.with(
         | 
| 16 16 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 17 | 
            -
                         | 
| 17 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), relation_type, 
         | 
| 18 | 
            +
                        an_instance_of(Gecode::Raw::SetVar))
         | 
| 18 19 | 
             
                    else
         | 
| 19 20 | 
             
                      Gecode::Raw.should_receive(:rel).once.with(
         | 
| 20 21 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 21 | 
            -
                         | 
| 22 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), relation_type, 
         | 
| 23 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), 
         | 
| 22 24 | 
             
                        an_instance_of(Gecode::Raw::BoolVar))
         | 
| 23 25 | 
             
                    end
         | 
| 24 26 | 
             
                  end
         | 
| @@ -65,11 +67,13 @@ describe Gecode::Constraints::Set::Relation, ' (equality)' do | |
| 65 67 | 
             
                    if reif_var.nil?
         | 
| 66 68 | 
             
                      Gecode::Raw.should_receive(:rel).once.with(
         | 
| 67 69 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 68 | 
            -
                         | 
| 70 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), relation_type, 
         | 
| 71 | 
            +
                        an_instance_of(Gecode::Raw::SetVar))
         | 
| 69 72 | 
             
                    else
         | 
| 70 73 | 
             
                      Gecode::Raw.should_receive(:rel).once.with(
         | 
| 71 74 | 
             
                        an_instance_of(Gecode::Raw::Space), 
         | 
| 72 | 
            -
                         | 
| 75 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), relation_type, 
         | 
| 76 | 
            +
                        an_instance_of(Gecode::Raw::SetVar), 
         | 
| 73 77 | 
             
                        an_instance_of(Gecode::Raw::BoolVar))
         | 
| 74 78 | 
             
                    end
         | 
| 75 79 | 
             
                  end
         | 
| @@ -134,7 +138,8 @@ describe Gecode::Constraints::Set::Relation, ' (elements)' do | |
| 134 138 | 
             
                    rhs = rhs.bind if rhs.respond_to? :bind
         | 
| 135 139 | 
             
                    Gecode::Raw.should_receive(:rel).once.with(
         | 
| 136 140 | 
             
                      an_instance_of(Gecode::Raw::Space), 
         | 
| 137 | 
            -
                       | 
| 141 | 
            +
                      an_instance_of(Gecode::Raw::SetVar), relation_type, 
         | 
| 142 | 
            +
                      an_instance_of(Gecode::Raw::IntVar))
         | 
| 138 143 | 
             
                  end
         | 
| 139 144 | 
             
                end
         | 
| 140 145 |  | 
    
        data/specs/int_var.rb
    CHANGED
    
    | @@ -75,7 +75,7 @@ describe Gecode::FreeIntVar, ' (with non-range domain of size > 1)' do | |
| 75 75 | 
             
              before do
         | 
| 76 76 | 
             
                @domain = [-3, -2, -1, 1]
         | 
| 77 77 | 
             
                model = Gecode::Model.new
         | 
| 78 | 
            -
                @var = model.int_var( | 
| 78 | 
            +
                @var = model.int_var(@domain)
         | 
| 79 79 | 
             
              end
         | 
| 80 80 |  | 
| 81 81 | 
             
              it_should_behave_like 'non-empty int variable'
         | 
| @@ -113,7 +113,7 @@ end | |
| 113 113 |  | 
| 114 114 | 
             
            describe Gecode::FreeIntVar, ' (assigned)' do
         | 
| 115 115 | 
             
              before do
         | 
| 116 | 
            -
                @domain =  | 
| 116 | 
            +
                @domain = 1
         | 
| 117 117 | 
             
                model = Gecode::Model.new
         | 
| 118 118 | 
             
                @var = model.int_var(*@domain)
         | 
| 119 119 | 
             
              end
         | 
| @@ -131,7 +131,7 @@ describe Gecode::FreeIntVar, ' (not assigned)' do | |
| 131 131 | 
             
              before do
         | 
| 132 132 | 
             
                @domain = 1..2
         | 
| 133 133 | 
             
                model = Gecode::Model.new
         | 
| 134 | 
            -
                @var = model.int_var( | 
| 134 | 
            +
                @var = model.int_var(@domain)
         | 
| 135 135 | 
             
              end
         | 
| 136 136 |  | 
| 137 137 | 
             
              it 'should not be assigned' do
         | 
    
        data/specs/model.rb
    CHANGED
    
    | @@ -10,10 +10,16 @@ describe Gecode::Model, ' (integer creation)' do | |
| 10 10 | 
             
                @model.int_var(range).should have_domain(range)
         | 
| 11 11 | 
             
              end
         | 
| 12 12 |  | 
| 13 | 
            -
               | 
| 13 | 
            +
              it 'should allow the creation of int variables without specified domain' do
         | 
| 14 | 
            +
                var = @model.int_var
         | 
| 15 | 
            +
                var.should be_range
         | 
| 16 | 
            +
                var.min.should == Gecode::Raw::Limits::Int::INT_MIN
         | 
| 17 | 
            +
                var.max.should == Gecode::Raw::Limits::Int::INT_MAX
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 14 20 | 
             
              it 'should allow the creation of int variables with non-range domains' do
         | 
| 15 21 | 
             
                domain = [1, 3, 5]
         | 
| 16 | 
            -
                @model.int_var( | 
| 22 | 
            +
                @model.int_var(domain).should have_domain(domain)
         | 
| 17 23 | 
             
              end
         | 
| 18 24 |  | 
| 19 25 | 
             
              it 'should allow the creation of int variables with single element domains' do
         | 
| @@ -21,11 +27,6 @@ describe Gecode::Model, ' (integer creation)' do | |
| 21 27 | 
             
                @model.int_var(domain).should have_domain([domain])
         | 
| 22 28 | 
             
              end
         | 
| 23 29 |  | 
| 24 | 
            -
              it 'should not accept empty domains' do
         | 
| 25 | 
            -
                lambda{ @model.int_var }.should raise_error(ArgumentError)
         | 
| 26 | 
            -
                lambda{ @model.int_var_array(1) }.should raise_error(ArgumentError)
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
              
         | 
| 29 30 | 
             
              it 'should allow the creation of int-var arrays with range domains' do
         | 
| 30 31 | 
             
                range = 0..3
         | 
| 31 32 | 
             
                count = 5
         | 
| @@ -37,7 +38,7 @@ describe Gecode::Model, ' (integer creation)' do | |
| 37 38 | 
             
              it 'should allow the creation of int-var arrays with non-range domains' do
         | 
| 38 39 | 
             
                domain = [1,3,5]
         | 
| 39 40 | 
             
                count = 5
         | 
| 40 | 
            -
                vars = @model.int_var_array(count,  | 
| 41 | 
            +
                vars = @model.int_var_array(count, domain)
         | 
| 41 42 | 
             
                vars.size.should equal(count)
         | 
| 42 43 | 
             
                vars.each{ |var| var.should have_domain(domain) }
         | 
| 43 44 | 
             
              end
         | 
| @@ -56,7 +57,7 @@ describe Gecode::Model, ' (integer creation)' do | |
| 56 57 | 
             
                domain = [1,3,5]
         | 
| 57 58 | 
             
                rows = 5
         | 
| 58 59 | 
             
                columns = 4
         | 
| 59 | 
            -
                vars = @model.int_var_matrix(rows, columns,  | 
| 60 | 
            +
                vars = @model.int_var_matrix(rows, columns, domain)
         | 
| 60 61 | 
             
                vars.row_size.should equal(rows)
         | 
| 61 62 | 
             
                vars.column_size.should equal(columns)
         | 
| 62 63 | 
             
                vars.each{ |var| var.should have_domain(domain) }
         | 
    
        data/specs/search.rb
    CHANGED
    
    | @@ -33,6 +33,26 @@ class SampleOptimizationProblem < Gecode::Model | |
| 33 33 | 
             
              end
         | 
| 34 34 | 
             
            end
         | 
| 35 35 |  | 
| 36 | 
            +
            class SampleOptimizationProblem2 < Gecode::Model
         | 
| 37 | 
            +
              attr :money
         | 
| 38 | 
            +
              
         | 
| 39 | 
            +
              def initialize
         | 
| 40 | 
            +
                @money = int_var_array(3, 0..9)
         | 
| 41 | 
            +
                @money.must_be.distinct
         | 
| 42 | 
            +
                @money.to_number.must < 500 # Otherwise it takes some time.
         | 
| 43 | 
            +
                
         | 
| 44 | 
            +
                branch_on @money, :variable => :smallest_size, :value => :min
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
            end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            class Array
         | 
| 49 | 
            +
              # Computes a number of the specified base using the array's elements as 
         | 
| 50 | 
            +
              # digits.
         | 
| 51 | 
            +
              def to_number(base = 10)
         | 
| 52 | 
            +
                inject{ |result, variable| variable + result * base }
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
            end
         | 
| 55 | 
            +
             | 
| 36 56 | 
             
            describe Gecode::Model, ' (with multiple solutions)' do
         | 
| 37 57 | 
             
              before do
         | 
| 38 58 | 
             
                @domain = 0..3
         | 
| @@ -175,12 +195,8 @@ describe Gecode::Model, ' (without constraints)' do | |
| 175 195 | 
             
            end
         | 
| 176 196 |  | 
| 177 197 | 
             
            describe Gecode::Model, '(optimization search)' do
         | 
| 178 | 
            -
              before do
         | 
| 179 | 
            -
                @model = SampleOptimizationProblem.new
         | 
| 180 | 
            -
              end
         | 
| 181 | 
            -
              
         | 
| 182 198 | 
             
              it 'should optimize the solution' do
         | 
| 183 | 
            -
                solution =  | 
| 199 | 
            +
                solution = SampleOptimizationProblem.new.optimize! do |model, best_so_far|
         | 
| 184 200 | 
             
                  model.z.must > best_so_far.z.value
         | 
| 185 201 | 
             
                end
         | 
| 186 202 | 
             
                solution.should_not be_nil
         | 
| @@ -189,9 +205,42 @@ describe Gecode::Model, '(optimization search)' do | |
| 189 205 | 
             
                solution.z.value.should == 25
         | 
| 190 206 | 
             
              end
         | 
| 191 207 |  | 
| 208 | 
            +
              it 'should not be bothered by garbage collecting' do
         | 
| 209 | 
            +
                # This goes through 400+ spaces.
         | 
| 210 | 
            +
                solution = SampleOptimizationProblem2.new.optimize! do |model, best_so_far|
         | 
| 211 | 
            +
                  model.money.to_number.must > best_so_far.money.values.to_number
         | 
| 212 | 
            +
                end
         | 
| 213 | 
            +
                solution.should_not be_nil
         | 
| 214 | 
            +
                solution.money.values.to_number.should == 498
         | 
| 215 | 
            +
              end
         | 
| 216 | 
            +
              
         | 
| 192 217 | 
             
              it 'should raise error if no constrain proc has been defined' do
         | 
| 193 218 | 
             
                lambda do 
         | 
| 194 219 | 
             
                  Gecode::Model.constrain(nil, nil) 
         | 
| 195 220 | 
             
                end.should raise_error(NotImplementedError)
         | 
| 196 221 | 
             
              end
         | 
| 222 | 
            +
              
         | 
| 223 | 
            +
              it 'should not have problems with variables being created in the optimization block' do
         | 
| 224 | 
            +
                solution = SampleOptimizationProblem.new.optimize! do |model, best_so_far|
         | 
| 225 | 
            +
                  tmp = model.int_var(0..25)
         | 
| 226 | 
            +
                  tmp.must == model.z
         | 
| 227 | 
            +
                  tmp.must > best_so_far.z.value
         | 
| 228 | 
            +
                end
         | 
| 229 | 
            +
                solution.should_not be_nil
         | 
| 230 | 
            +
                solution.x.value.should == 5
         | 
| 231 | 
            +
                solution.y.value.should == 5
         | 
| 232 | 
            +
                solution.z.value.should == 25
         | 
| 233 | 
            +
              end
         | 
| 234 | 
            +
             | 
| 235 | 
            +
              it 'should not have problems with variables being created in the optimization block (2)' do
         | 
| 236 | 
            +
                solution = SampleOptimizationProblem.new.optimize! do |model, best_so_far|
         | 
| 237 | 
            +
                  tmp = model.int_var(0..25)
         | 
| 238 | 
            +
                  tmp.must == model.z
         | 
| 239 | 
            +
                  (tmp + tmp).must > best_so_far.z.value*2
         | 
| 240 | 
            +
                end
         | 
| 241 | 
            +
                solution.should_not be_nil
         | 
| 242 | 
            +
                solution.x.value.should == 5
         | 
| 243 | 
            +
                solution.y.value.should == 5
         | 
| 244 | 
            +
                solution.z.value.should == 25
         | 
| 245 | 
            +
              end
         | 
| 197 246 | 
             
            end
         | 
    
        data/specs/spec_helper.rb
    CHANGED
    
    
    
        data/tasks/distribution.rake
    CHANGED
    
    | @@ -15,6 +15,11 @@ spec = Gem::Specification.new do |s| | |
| 15 15 | 
             
              s.name = PKG_NAME
         | 
| 16 16 | 
             
              s.version = GecodeR::VERSION
         | 
| 17 17 | 
             
              s.summary = 'Ruby interface to Gecode, an environment for constraint programming.'
         | 
| 18 | 
            +
              s.description = <<-end_description
         | 
| 19 | 
            +
                Gecode/R is a Ruby interface to the Gecode constraint programming library. 
         | 
| 20 | 
            +
                Gecode/R is intended for people with no previous experience of constraint 
         | 
| 21 | 
            +
                programming, aiming to be easy to pick up and use.
         | 
| 22 | 
            +
              end_description
         | 
| 18 23 |  | 
| 19 24 | 
             
              s.files = FileList[
         | 
| 20 25 | 
             
                '[A-Z]*',
         | 
| @@ -28,14 +33,16 @@ spec = Gem::Specification.new do |s| | |
| 28 33 | 
             
              ].to_a
         | 
| 29 34 | 
             
              s.require_path = 'lib'
         | 
| 30 35 | 
             
              s.extensions << 'ext/extconf.rb'
         | 
| 36 | 
            +
              s.requirements << 'Gecode 1.3.1'
         | 
| 31 37 |  | 
| 32 38 | 
             
              s.has_rdoc = true
         | 
| 33 39 | 
             
              s.rdoc_options = rd.options
         | 
| 34 40 | 
             
              s.extra_rdoc_files = rd.rdoc_files
         | 
| 41 | 
            +
              s.test_files = FileList['specs/**/*.rb']
         | 
| 35 42 |  | 
| 36 43 | 
             
              s.autorequire = 'gecoder'
         | 
| 37 44 | 
             
              s.author = ["Gecode/R Development Team"]
         | 
| 38 | 
            -
              s.email = "gecoder- | 
| 45 | 
            +
              s.email = "gecoder-users@rubyforge.org"
         | 
| 39 46 | 
             
              s.homepage = "http://gecoder.rubyforge.org"
         | 
| 40 47 | 
             
              s.rubyforge_project = "gecoder"
         | 
| 41 48 | 
             
            end
         | 
    
        data/tasks/specs.rake
    CHANGED
    
    
    
        data/vendor/rust/rust/class.rb
    CHANGED
    
    | @@ -28,8 +28,9 @@ require 'rust/type' | |
| 28 28 | 
             
            module Rust
         | 
| 29 29 | 
             
              class Class < Container
         | 
| 30 30 | 
             
                attr_accessor :bindname
         | 
| 31 | 
            +
                attr_accessor :function_mark
         | 
| 31 32 | 
             
                attr_reader :name, :cname
         | 
| 32 | 
            -
                attr_reader :varname, :varcname, :ptrmap, :function_free, :parent_varname
         | 
| 33 | 
            +
                attr_reader :varname, :varcname, :ptrmap, :function_free, :function_map_free, :parent_varname
         | 
| 33 34 |  | 
| 34 35 | 
             
                # Rust::Namespace object for the class, used to get the proper C++
         | 
| 35 36 | 
             
                # name.
         | 
| @@ -52,6 +53,8 @@ module Rust | |
| 52 53 |  | 
| 53 54 | 
             
                  @ptrmap = "#{type.valid_name}Map"
         | 
| 54 55 | 
             
                  @function_free = "#{varname}_free"
         | 
| 56 | 
            +
                  @function_map_free = "#{varname}_free_map_entry"
         | 
| 57 | 
            +
                  @function_mark = "#{varname}_mark"
         | 
| 55 58 |  | 
| 56 59 | 
             
                  @cname = @namespace.cname ? "#{@namespace.cname}::#{@name}" : @name
         | 
| 57 60 |  | 
| @@ -69,6 +72,8 @@ module Rust | |
| 69 72 | 
             
                  add_expansion 'bind_name', '@bindname'
         | 
| 70 73 | 
             
                  add_expansion 'class_ptrmap', 'ptrmap'
         | 
| 71 74 | 
             
                  add_expansion 'class_free_function', '@function_free'
         | 
| 75 | 
            +
                  add_expansion 'class_map_free_function', '@function_map_free'
         | 
| 76 | 
            +
                  add_expansion 'class_mark_function', '@function_mark'
         | 
| 72 77 | 
             
                  add_expansion 'parent_varname', '@parent_varname'
         | 
| 73 78 | 
             
                end
         | 
| 74 79 |  | 
| @@ -69,11 +69,11 @@ VALUE cxx2ruby(!c_class_name!* instance, bool free) { | |
| 69 69 | 
             
                  VALUE rval;
         | 
| 70 70 | 
             
                  if( !free )
         | 
| 71 71 | 
             
                  {
         | 
| 72 | 
            -
                    rval = Data_Wrap_Struct(klass, 0,  | 
| 72 | 
            +
                    rval = Data_Wrap_Struct(klass, 0, !class_map_free_function!, (void*)instance);
         | 
| 73 73 | 
             
                  }
         | 
| 74 74 | 
             
                  else
         | 
| 75 75 | 
             
                  {
         | 
| 76 | 
            -
                    rval = Data_Wrap_Struct(klass,  | 
| 76 | 
            +
                    rval = Data_Wrap_Struct(klass, !class_mark_function!, !class_free_function!, (void*)instance);
         | 
| 77 77 | 
             
                  }
         | 
| 78 78 |  | 
| 79 79 | 
             
                  !class_ptrmap![rval] = instance;
         | 
| @@ -87,5 +87,5 @@ VALUE cxx2ruby(!c_class_name!* instance, bool free) { | |
| 87 87 | 
             
            }
         | 
| 88 88 |  | 
| 89 89 | 
             
            static VALUE !class_varname!_alloc(VALUE self) {
         | 
| 90 | 
            -
               return Data_Wrap_Struct(self,  | 
| 90 | 
            +
               return Data_Wrap_Struct(self, !class_mark_function!, !class_free_function!, 0);
         | 
| 91 91 | 
             
            }
         | 
| @@ -3,10 +3,24 @@ | |
| 3 3 | 
             
            T!class_ptrmap! !class_ptrmap!;
         | 
| 4 4 |  | 
| 5 5 | 
             
            static void !class_varname!_free(void *p) {
         | 
| 6 | 
            +
            	!class_map_free_function!(p);
         | 
| 7 | 
            +
              delete (!c_class_name!*)p;
         | 
| 8 | 
            +
            }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            static void !class_varname!_free_map_entry(void *p) {
         | 
| 11 | 
            +
            #ifdef DEBUG      
         | 
| 12 | 
            +
              fprintf(stderr, "rust: Freeing %p (!class_varname!) \\n", p);
         | 
| 13 | 
            +
            #endif
         | 
| 14 | 
            +
             | 
| 6 15 | 
             
              T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
         | 
| 7 16 | 
             
              for(it = !class_ptrmap!.begin(); it != eend; it++)
         | 
| 8 17 | 
             
                 if ( (*it).second == (!c_class_name!*)p ) {
         | 
| 9 18 | 
             
                    !class_ptrmap!.erase(it); break;
         | 
| 10 19 | 
             
                 }
         | 
| 11 | 
            -
             | 
| 20 | 
            +
            }
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            static void !class_varname!_mark(void *p) {
         | 
| 23 | 
            +
            #ifdef DEBUG      
         | 
| 24 | 
            +
              fprintf(stderr, "rust: Marking %p (!class_varname!) \\n", p);
         | 
| 25 | 
            +
            #endif
         | 
| 12 26 | 
             
            }
         | 
    
        metadata
    CHANGED
    
    | @@ -1,17 +1,17 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            -
            rubygems_version: 0.9. | 
| 2 | 
            +
            rubygems_version: 0.9.4
         | 
| 3 3 | 
             
            specification_version: 1
         | 
| 4 4 | 
             
            name: gecoder
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 0.6. | 
| 7 | 
            -
            date: 2007-07- | 
| 6 | 
            +
              version: 0.6.1
         | 
| 7 | 
            +
            date: 2007-07-23 00:00:00 +02:00
         | 
| 8 8 | 
             
            summary: Ruby interface to Gecode, an environment for constraint programming.
         | 
| 9 9 | 
             
            require_paths: 
         | 
| 10 10 | 
             
            - lib
         | 
| 11 | 
            -
            email: gecoder- | 
| 11 | 
            +
            email: gecoder-users@rubyforge.org
         | 
| 12 12 | 
             
            homepage: http://gecoder.rubyforge.org
         | 
| 13 13 | 
             
            rubyforge_project: gecoder
         | 
| 14 | 
            -
            description: 
         | 
| 14 | 
            +
            description: Gecode/R is a Ruby interface to the Gecode constraint programming library.  Gecode/R is intended for people with no previous experience of constraint  programming, aiming to be easy to pick up and use.
         | 
| 15 15 | 
             
            autorequire: gecoder
         | 
| 16 16 | 
             
            default_executable: 
         | 
| 17 17 | 
             
            bindir: bin
         | 
| @@ -51,8 +51,8 @@ files: | |
| 51 51 | 
             
            - lib/gecoder/interface/constraints/int_var_constraints.rb
         | 
| 52 52 | 
             
            - lib/gecoder/interface/constraints/int_enum_constraints.rb
         | 
| 53 53 | 
             
            - lib/gecoder/interface/constraints/bool_enum_constraints.rb
         | 
| 54 | 
            -
            - lib/gecoder/interface/constraints/set_var_constraints.rb
         | 
| 55 54 | 
             
            - lib/gecoder/interface/constraints/set_enum_constraints.rb
         | 
| 55 | 
            +
            - lib/gecoder/interface/constraints/set_var_constraints.rb
         | 
| 56 56 | 
             
            - lib/gecoder/interface/constraints/bool/boolean.rb
         | 
| 57 57 | 
             
            - lib/gecoder/interface/constraints/int/linear.rb
         | 
| 58 58 | 
             
            - lib/gecoder/interface/constraints/int/domain.rb
         | 
| @@ -65,12 +65,12 @@ files: | |
| 65 65 | 
             
            - lib/gecoder/interface/constraints/int_enum/sort.rb
         | 
| 66 66 | 
             
            - lib/gecoder/interface/constraints/int_enum/arithmetic.rb
         | 
| 67 67 | 
             
            - lib/gecoder/interface/constraints/bool_enum/boolean.rb
         | 
| 68 | 
            -
            - lib/gecoder/interface/constraints/set/domain.rb
         | 
| 69 | 
            -
            - lib/gecoder/interface/constraints/set/relation.rb
         | 
| 70 | 
            -
            - lib/gecoder/interface/constraints/set/connection.rb
         | 
| 71 | 
            -
            - lib/gecoder/interface/constraints/set/cardinality.rb
         | 
| 72 68 | 
             
            - lib/gecoder/interface/constraints/set_enum/distinct.rb
         | 
| 73 69 | 
             
            - lib/gecoder/interface/constraints/set_enum/channel.rb
         | 
| 70 | 
            +
            - lib/gecoder/interface/constraints/set/connection.rb
         | 
| 71 | 
            +
            - lib/gecoder/interface/constraints/set/relation.rb
         | 
| 72 | 
            +
            - lib/gecoder/interface/constraints/set/cardinality.rb
         | 
| 73 | 
            +
            - lib/gecoder/interface/constraints/set/domain.rb
         | 
| 74 74 | 
             
            - lib/gecoder/bindings/bindings.rb
         | 
| 75 75 | 
             
            - example/example_helper.rb
         | 
| 76 76 | 
             
            - example/raw_bindings.rb
         | 
| @@ -78,6 +78,7 @@ files: | |
| 78 78 | 
             
            - example/queens.rb
         | 
| 79 79 | 
             
            - example/sudoku.rb
         | 
| 80 80 | 
             
            - example/magic_sequence.rb
         | 
| 81 | 
            +
            - example/send_most_money.rb
         | 
| 81 82 | 
             
            - vendor/rust
         | 
| 82 83 | 
             
            - vendor/rust/test
         | 
| 83 84 | 
             
            - vendor/rust/include
         | 
| @@ -160,22 +161,22 @@ files: | |
| 160 161 | 
             
            - specs/set_var.rb
         | 
| 161 162 | 
             
            - specs/logging.rb
         | 
| 162 163 | 
             
            - specs/constraints/linear.rb
         | 
| 163 | 
            -
            - specs/constraints/set_relation.rb
         | 
| 164 164 | 
             
            - specs/constraints/distinct.rb
         | 
| 165 165 | 
             
            - specs/constraints/constraint_helper.rb
         | 
| 166 166 | 
             
            - specs/constraints/constraints.rb
         | 
| 167 167 | 
             
            - specs/constraints/boolean.rb
         | 
| 168 168 | 
             
            - specs/constraints/reification_sugar.rb
         | 
| 169 | 
            +
            - specs/constraints/bool_enum.rb
         | 
| 169 170 | 
             
            - specs/constraints/equality.rb
         | 
| 170 171 | 
             
            - specs/constraints/channel.rb
         | 
| 171 172 | 
             
            - specs/constraints/element.rb
         | 
| 172 173 | 
             
            - specs/constraints/count.rb
         | 
| 173 174 | 
             
            - specs/constraints/sort.rb
         | 
| 174 175 | 
             
            - specs/constraints/arithmetic.rb
         | 
| 175 | 
            -
            - specs/constraints/bool_enum.rb
         | 
| 176 176 | 
             
            - specs/constraints/int_domain.rb
         | 
| 177 177 | 
             
            - specs/constraints/set_domain.rb
         | 
| 178 178 | 
             
            - specs/constraints/int_relation.rb
         | 
| 179 | 
            +
            - specs/constraints/set_relation.rb
         | 
| 179 180 | 
             
            - specs/constraints/connection.rb
         | 
| 180 181 | 
             
            - specs/constraints/cardinality.rb
         | 
| 181 182 | 
             
            - ext/missing.h
         | 
| @@ -183,8 +184,37 @@ files: | |
| 183 184 | 
             
            - ext/vararray.cpp
         | 
| 184 185 | 
             
            - ext/missing.cpp
         | 
| 185 186 | 
             
            - ext/vararray.h
         | 
| 186 | 
            -
            test_files:  | 
| 187 | 
            -
             | 
| 187 | 
            +
            test_files: 
         | 
| 188 | 
            +
            - specs/search.rb
         | 
| 189 | 
            +
            - specs/model.rb
         | 
| 190 | 
            +
            - specs/branch.rb
         | 
| 191 | 
            +
            - specs/binding_changes.rb
         | 
| 192 | 
            +
            - specs/spec_helper.rb
         | 
| 193 | 
            +
            - specs/enum_wrapper.rb
         | 
| 194 | 
            +
            - specs/int_var.rb
         | 
| 195 | 
            +
            - specs/bool_var.rb
         | 
| 196 | 
            +
            - specs/enum_matrix.rb
         | 
| 197 | 
            +
            - specs/set_var.rb
         | 
| 198 | 
            +
            - specs/logging.rb
         | 
| 199 | 
            +
            - specs/constraints/linear.rb
         | 
| 200 | 
            +
            - specs/constraints/distinct.rb
         | 
| 201 | 
            +
            - specs/constraints/constraint_helper.rb
         | 
| 202 | 
            +
            - specs/constraints/constraints.rb
         | 
| 203 | 
            +
            - specs/constraints/boolean.rb
         | 
| 204 | 
            +
            - specs/constraints/reification_sugar.rb
         | 
| 205 | 
            +
            - specs/constraints/bool_enum.rb
         | 
| 206 | 
            +
            - specs/constraints/equality.rb
         | 
| 207 | 
            +
            - specs/constraints/channel.rb
         | 
| 208 | 
            +
            - specs/constraints/element.rb
         | 
| 209 | 
            +
            - specs/constraints/count.rb
         | 
| 210 | 
            +
            - specs/constraints/sort.rb
         | 
| 211 | 
            +
            - specs/constraints/arithmetic.rb
         | 
| 212 | 
            +
            - specs/constraints/int_domain.rb
         | 
| 213 | 
            +
            - specs/constraints/set_domain.rb
         | 
| 214 | 
            +
            - specs/constraints/int_relation.rb
         | 
| 215 | 
            +
            - specs/constraints/set_relation.rb
         | 
| 216 | 
            +
            - specs/constraints/connection.rb
         | 
| 217 | 
            +
            - specs/constraints/cardinality.rb
         | 
| 188 218 | 
             
            rdoc_options: 
         | 
| 189 219 | 
             
            - --title
         | 
| 190 220 | 
             
            - Gecode/R
         | 
| @@ -211,8 +241,8 @@ extra_rdoc_files: | |
| 211 241 | 
             
            - lib/gecoder/interface/constraints/int_var_constraints.rb
         | 
| 212 242 | 
             
            - lib/gecoder/interface/constraints/int_enum_constraints.rb
         | 
| 213 243 | 
             
            - lib/gecoder/interface/constraints/bool_enum_constraints.rb
         | 
| 214 | 
            -
            - lib/gecoder/interface/constraints/set_var_constraints.rb
         | 
| 215 244 | 
             
            - lib/gecoder/interface/constraints/set_enum_constraints.rb
         | 
| 245 | 
            +
            - lib/gecoder/interface/constraints/set_var_constraints.rb
         | 
| 216 246 | 
             
            - lib/gecoder/interface/constraints/bool/boolean.rb
         | 
| 217 247 | 
             
            - lib/gecoder/interface/constraints/int/linear.rb
         | 
| 218 248 | 
             
            - lib/gecoder/interface/constraints/int/domain.rb
         | 
| @@ -225,18 +255,18 @@ extra_rdoc_files: | |
| 225 255 | 
             
            - lib/gecoder/interface/constraints/int_enum/sort.rb
         | 
| 226 256 | 
             
            - lib/gecoder/interface/constraints/int_enum/arithmetic.rb
         | 
| 227 257 | 
             
            - lib/gecoder/interface/constraints/bool_enum/boolean.rb
         | 
| 228 | 
            -
            - lib/gecoder/interface/constraints/set/domain.rb
         | 
| 229 | 
            -
            - lib/gecoder/interface/constraints/set/relation.rb
         | 
| 230 | 
            -
            - lib/gecoder/interface/constraints/set/connection.rb
         | 
| 231 | 
            -
            - lib/gecoder/interface/constraints/set/cardinality.rb
         | 
| 232 258 | 
             
            - lib/gecoder/interface/constraints/set_enum/distinct.rb
         | 
| 233 259 | 
             
            - lib/gecoder/interface/constraints/set_enum/channel.rb
         | 
| 260 | 
            +
            - lib/gecoder/interface/constraints/set/connection.rb
         | 
| 261 | 
            +
            - lib/gecoder/interface/constraints/set/relation.rb
         | 
| 262 | 
            +
            - lib/gecoder/interface/constraints/set/cardinality.rb
         | 
| 263 | 
            +
            - lib/gecoder/interface/constraints/set/domain.rb
         | 
| 234 264 | 
             
            - lib/gecoder/bindings/bindings.rb
         | 
| 235 265 | 
             
            executables: []
         | 
| 236 266 |  | 
| 237 267 | 
             
            extensions: 
         | 
| 238 268 | 
             
            - ext/extconf.rb
         | 
| 239 | 
            -
            requirements:  | 
| 240 | 
            -
             | 
| 269 | 
            +
            requirements: 
         | 
| 270 | 
            +
            - Gecode 1.3.1
         | 
| 241 271 | 
             
            dependencies: []
         | 
| 242 272 |  |