Class: MIPPeR::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/mipper/model.rb

Overview

Stores a linear programming model for a particular solver

Direct Known Subclasses

CbcModel, GLPKModel, GurobiModel, LPSolveModel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModel

Returns a new instance of Model.



6
7
8
9
10
11
12
13
14
15
# File 'lib/mipper/model.rb', line 6

def initialize
  @solution = nil
  @sense = :min

  @variables = []
  @constraints = []

  @pending_variables = []
  @pending_constraints = []
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



4
5
6
# File 'lib/mipper/model.rb', line 4

def constraints
  @constraints
end

#variablesObject (readonly)

Returns the value of attribute variables.



4
5
6
# File 'lib/mipper/model.rb', line 4

def variables
  @variables
end

Instance Method Details

#<<(obj) ⇒ Object

Add new objects (variables and constraints) to the model



18
19
20
21
22
23
24
25
26
27
# File 'lib/mipper/model.rb', line 18

def <<(obj)
  case obj
  when Variable
    @pending_variables << obj
  when Constraint
    @pending_constraints << obj
  else
    fail TypeError
  end
end

#compute_iisObject

Compute an irreducible inconsistent subsytem for the model



65
66
67
# File 'lib/mipper/model.rb', line 65

def compute_iis
  fail NotImplementedError
end

#objective_valueObject

Get the value of the objective function from a previous solution



70
71
72
# File 'lib/mipper/model.rb', line 70

def objective_value
  @solution.objective_value unless @solution.nil?
end

#optimizeObject

Optimize the model



51
52
53
# File 'lib/mipper/model.rb', line 51

def optimize
  fail NotImplementedError
end

#sense=(_sense) ⇒ Object

Set the sense of the model



46
47
48
# File 'lib/mipper/model.rb', line 46

def sense=(_sense)
  fail NotImplementedError
end

#statusObject

Get the status of the model



56
57
58
59
60
61
62
# File 'lib/mipper/model.rb', line 56

def status
  if @solution.nil?
    :unknown
  else
    @solution.status
  end
end

#updateObject

Update the model



30
31
32
33
# File 'lib/mipper/model.rb', line 30

def update
  update_variables
  update_constraints
end

#variable_value(var) ⇒ Object

Get the value of a variable from a previous solution



75
76
77
# File 'lib/mipper/model.rb', line 75

def variable_value(var)
  @solution.variable_values[var.index] unless @solution.nil?
end

#write_lp(_filename) ⇒ Object

Write the model to a file in CPLEX LP format



36
37
38
# File 'lib/mipper/model.rb', line 36

def write_lp(_filename)
  fail NotImplementedError
end

#write_mps(_filename) ⇒ Object

Write the model to a file in MPS format



41
42
43
# File 'lib/mipper/model.rb', line 41

def write_mps(_filename)
  fail NotImplementedError
end