Sha256: fc135fee6f49f8befdbd246f47777ace644bf9728b6c102731b38f5fb8132bc9
Contents?: true
Size: 1.7 KB
Versions: 2
Compression:
Stored size: 1.7 KB
Contents
module Gecode class FreeSetVar # Starts a constraint on the size of the set. def size params = {:lhs => self} Gecode::Constraints::Set::Cardinality::SizeExpressionStub.new(@model, params) end end end module Gecode::Constraints::Set # A module that gathers the classes and modules used in cardinality # constraints. module Cardinality # Describes a cardinality constraint. class CardinalityConstraint < Gecode::Constraints::Constraint def post var, range = @params.values_at(:lhs, :range) Gecode::Raw::cardinality(@model.active_space, var.bind, range.first, range.last) end end # A custom composite stub to change the composite expression used. class CompositeStub < Gecode::Constraints::CompositeStub def initialize(model, params) super(Expression, model, params) end end # Describes a cardinality expression started with set.size.must . class Expression < Gecode::Constraints::Int::CompositeExpression def in(range) if range.kind_of?(Range) and !@params[:negate] @params.update(:range => range) @model.add_constraint CardinalityConstraint.new(@model, @params) else super(range) end end end # Describes an expression stub started with a set variable followed by # #size . class SizeExpressionStub < CompositeStub def constrain_equal(variable, params, constrain) lhs = @params[:lhs] if constrain variable.must_be.in lhs.lower_bound.size..lhs.upper_bound.size end Gecode::Raw::cardinality(@model.active_space, lhs.bind, variable.bind) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gecoder-0.7.0 | lib/gecoder/interface/constraints/set/cardinality.rb |
gecoder-0.6.1 | lib/gecoder/interface/constraints/set/cardinality.rb |