Class: Ilp::Objective

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-cbc/ilp/objective.rb

Constant Summary collapse

MINIMIZE =
:min
MAXIMIZE =
:max

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(terms, objective_function = MAXIMIZE) ⇒ Objective

Returns a new instance of Objective.



7
8
9
10
11
12
13
14
# File 'lib/ruby-cbc/ilp/objective.rb', line 7

def initialize(terms, objective_function = MAXIMIZE)
  @terms = terms
  @terms = Ilp::Term.new(@terms) if @terms.is_a? Ilp::Var
  @terms = Ilp::TermArray.new([@terms]) if @terms.is_a? Ilp::Term
  @terms.normalize!
  @terms.send(:pop_constant)
  @objective_function = objective_function
end

Instance Attribute Details

#objective_functionObject (readonly)

Returns the value of attribute objective_function.



6
7
8
# File 'lib/ruby-cbc/ilp/objective.rb', line 6

def objective_function
  @objective_function
end

#termsObject (readonly)

Returns the value of attribute terms.



6
7
8
# File 'lib/ruby-cbc/ilp/objective.rb', line 6

def terms
  @terms
end

Instance Method Details

#to_sObject



16
17
18
# File 'lib/ruby-cbc/ilp/objective.rb', line 16

def to_s
  "#{(@objective_function == :max ? 'Maximize' : 'Minimize')}\n  #{terms}"
end