Class: ORTools::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/or_tools/solver.rb

Instance Method Summary collapse

Instance Method Details

#add(expr) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/or_tools/solver.rb', line 7

def add(expr)
  left, op, const = Utils.index_constraint(expr)

  constraint =
    case op
    when :<=
      self.constraint(-infinity, const)
    when :>=
      self.constraint(const, infinity)
    when :==
      self.constraint(const, const)
    else
      raise ArgumentError, "Supported operations are ==, <=, and >="
    end
  left.each do |var, c|
    constraint.set_coefficient(var, c)
  end
  nil
end

#maximize(expr) ⇒ Object



27
28
29
30
# File 'lib/or_tools/solver.rb', line 27

def maximize(expr)
  set_objective(expr)
  objective.set_maximization
end

#minimize(expr) ⇒ Object



32
33
34
35
# File 'lib/or_tools/solver.rb', line 32

def minimize(expr)
  set_objective(expr)
  objective.set_minimization
end

#solve(parameters = nil) ⇒ Object



37
38
39
40
# File 'lib/or_tools/solver.rb', line 37

def solve(parameters = nil)
  parameters ||= MPSolverParameters.new
  _solve(parameters)
end

#sum(arr) ⇒ Object



3
4
5
# File 'lib/or_tools/solver.rb', line 3

def sum(arr)
  Expression.new(arr)
end