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.



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

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!
  cste = @terms.send(:pop_constant)
  puts "Removing constant [#{cste}] in objective" if cste != 0
  @objective_function = objective_function
end

Instance Attribute Details

#objective_functionObject

Returns the value of attribute objective_function.



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

def objective_function
  @objective_function
end

#termsObject

Returns the value of attribute terms.



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

def terms
  @terms
end

Instance Method Details

#to_sObject



18
19
20
21
22
23
# File 'lib/ruby-cbc/ilp/objective.rb', line 18

def to_s
  str = ""
  str << (@objective_function == :max ? "Maximize" : "Minimize")
  str << "\n  "
  str << terms.to_s
end