Class: Gecode::Util::SetVarStore
- Inherits:
-
Object
- Object
- Gecode::Util::SetVarStore
- Includes:
- VarStoreMethods
- Defined in:
- lib/gecoder/interface/binding_changes.rb
Overview
A store in which int variables are created and stored.
Instance Method Summary collapse
-
#initialize(space) ⇒ SetVarStore
constructor
Creates a store for the specified space with the specified capacit.
-
#new_vars(glb_domain, lub_domain, cardinality_range = nil, count = 1) ⇒ Object
Creates the specified number of set variables in the space with the specified domain for greatest lower bound and least upper bound (specified as either a range or enum).
Methods included from VarStoreMethods
Constructor Details
#initialize(space) ⇒ SetVarStore
Creates a store for the specified space with the specified capacit.
254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/gecoder/interface/binding_changes.rb', line 254 def initialize(space) @space = space @var_array = space.set_var_array(ARRAY_IDENTIFIER) if @var_array.nil? # Create a new one. @var_array = new_storage_array(0) end @size = @var_array.size @next_index = @size end |
Instance Method Details
#new_vars(glb_domain, lub_domain, cardinality_range = nil, count = 1) ⇒ Object
Creates the specified number of set variables in the space with the specified domain for greatest lower bound and least upper bound (specified as either a range or enum). A range for the allowed cardinality of the set can also be specified, if none is specified, or nil is given, then the default range (anything) will be used. Returns the indices with which they can then be accessed using set_var.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/gecoder/interface/binding_changes.rb', line 273 def new_vars(glb_domain, lub_domain, cardinality_range = nil, count = 1) grow(@next_index + count) # See the design note for more information. if cardinality_range.nil? cardinality_range = 0..Gecode::Raw::Limits::Set::CARD_MAX end params = [@space] params << domain_to_args(glb_domain) params << domain_to_args(lub_domain) params << cardinality_range.first << cardinality_range.last count.times do |i| @var_array[@next_index] = Gecode::Raw::SetVar.new(*params.flatten) @next_index += 1 end ((@next_index - count)...@next_index).to_a end |