module Gecode
Problems can be formulated and solved either through defining a new class that mixes in Gecode::Mixin or by using ::solve et al. Gecode::Mixin describes how to formulate problems.
Examples ¶ ↑
The following two examples show how to solve the following equation system, using both ways to define and solve a problem.
Equation system:
x + y = z x = y - 3 0 <= x,y,z <= 9
Mixing in Gecode::Mixin¶ ↑
class EquationProblem include Gecode::Mixin def initialize variables_is_an int_var_array(3, 0..9) x, y, z = variables (x + y).must == z x.must == y - 3 branch_on variables end end puts EquationProblem.new.solve!.variables.join(' ')
Using ::solve¶ ↑
solution = Gecode.solve do variables_is_an int_var_array(3, 0..9) x, y, z = variables (x + y).must == z x.must == y - 3 branch_on variables end puts solution.variables.values.join(' ')
Constants
- BoolVar
- IntVar
- Raw
We just make Gecode::Raw an alias of the real module.
- SetVar
Public Class Methods
Provides a convenient way to construct a model and then find the solution that maximizes a given variable. The model constructed uses the specified block as initialization method. The solution that maximizes the specified variable is then returned.
For instance
solution = Gecode.maximize :variable_bar do # Do something end
is equivalent to
class Foo include Gecode::Mixin def initialize # Do something end end solution = Foo.new.maximize :variable_bar
# File lib/gecoder/interface/convenience.rb, line 55 def self.maximize(variable_to_maximize, &block) create_model(&block).maximize! variable_to_maximize end
Provides a convenient way to construct a model and then find the solution that minimizes a given variable. The model constructed uses the specified block as initialization method. The solution that minimizes the specified variable is then returned.
For instance
solution = Gecode.minimize :variable_bar do # Do something end
is equivalent to
class Foo include Gecode::Mixin def initialize # Do something end end solution = Foo.new.minimize :variable_bar
# File lib/gecoder/interface/convenience.rb, line 80 def self.minimize(variable_to_minimize, &block) create_model(&block).minimize! variable_to_minimize end
Provides a convenient way to construct a model and then find a solution. The model constructed uses the specified block as initialization method. The first solution to the model is then returned.
For instance
solution = Gecode.solve do # Do something end
is equivalent to
class Foo include Gecode::Mixin def initialize # Do something end end solution = Foo.new.solve!
# File lib/gecoder/interface/convenience.rb, line 30 def self.solve(&block) create_model(&block).solve! end