Sha256: e70357afebff5f47a742e888c9c6a5f520eb344db9e028eeba6459cd7538d3b4

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

class ReifSugarSampleProblem < Gecode::Model
  attr :x
  attr :y
  attr :z
  
  def initialize
    @x = int_var(0..1)
    @y = int_var(1..2)
    @z = int_var(3..4)
    branch_on wrap_enum([@x, @y, @z])
  end
end

describe Gecode::ReifiableConstraint do
  before do
    @model = ReifSugarSampleProblem.new
    @x = @model.x
    @y = @model.y
    @z = @model.z
  end

  it 'should fail disjunctions if neither side can be satisfied' do
    (@x.must == 3) | (@y.must == 3)
    lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
  end
  
  it 'should solve disjunctions' do
    (@x.must > 0) | (@y.must == 3)
    sol = @model.solve!
    sol.should_not be_nil
    sol.x.should have_domain([1])
  end
  
  it 'should fail conjunctions if one side can\'t be satisfied' do
    (@x.must > 3) & (@y.must == 3)
    lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
  end

  it 'should solve conjunctions' do
    (@x.must > 0) & (@y.must == 2)
    sol = @model.solve!
    sol.should_not be_nil
    sol.x.should have_domain([1])
    sol.y.should have_domain([2])
  end

  it 'should handle the same variable being used multiple times' do
    (@z.must == 4) | (@z.must == 4)
    sol = @model.solve!
    sol.should_not be_nil
    sol.z.should have_domain([4])
  end
  
  it 'should handle nested operations' do
    ((@x.must > 3) & (@y.must == 2)) | (@z.must == 4) | (
      (@x.must == 0) & (@z.must == 4))
    sol = @model.solve!
    sol.should_not be_nil
    sol.x.should have_domain([0])
    sol.z.should have_domain([4])
  end
  
  it 'should handle negations' do
    (@z.must_not == 4) & (@z.must == 4)
    lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
gecoder-0.9.0 specs/constraints/reification_sugar.rb
gecoder-with-gecode-0.9.0-x86-mswin32-60 specs/constraints/reification_sugar.rb
gecoder-with-gecode-0.9.0 specs/constraints/reification_sugar.rb