Module: Rulp

Extended by:
Log
Defined in:
lib/rulp/rulp.rb,
lib/helpers/log.rb,
lib/rulp/version.rb,
lib/rulp/rulp_bounds.rb,
lib/rulp/rulp_initializers.rb

Defined Under Namespace

Modules: Bounds, Initializers, Log Classes: Problem

Constant Summary collapse

MIN =
"Minimize"
MAX =
"Maximize"
GLPK =
::GLPK
GUROBI =
::GUROBI
SCIP =
::SCIP
CBC =
::CBC
SOLVERS =
{
  GLPK     => Glpk,
  SCIP     => Scip,
  CBC      => Cbc,
  GUROBI   => Gurobi,
}
VERSION =
'0.0.44'

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Log

log, log_level, log_level=, logger, logger=, print_solver_outputs, print_solver_outputs=

Instance Attribute Details

#expressionsObject

Returns the value of attribute expressions


23
24
25
# File 'lib/rulp/rulp.rb', line 23

def expressions
  @expressions
end

Class Method Details

.Cbc(lp, opts = {}) ⇒ Object


47
48
49
# File 'lib/rulp/rulp.rb', line 47

def self.Cbc(lp, opts={})
  lp.solve_with(CBC, opts)
end

.exec(command) ⇒ Object


75
76
77
78
79
80
81
82
# File 'lib/rulp/rulp.rb', line 75

def self.exec(command)
  Open3.popen2e("#{command} #{Rulp.print_solver_outputs ? "" : "> /dev/null 2>&1"}") do | inp, out, thr|
    out.each.map do |line|
      Rulp.log(Logger::DEBUG, line)
      line
    end
  end.join
end

.Glpk(lp, opts = {}) ⇒ Object


43
44
45
# File 'lib/rulp/rulp.rb', line 43

def self.Glpk(lp, opts={})
  lp.solve_with(GLPK, opts)
end

.Gurobi(lp, opts = {}) ⇒ Object


55
56
57
# File 'lib/rulp/rulp.rb', line 55

def self.Gurobi(lp, opts={})
  lp.solve_with(GUROBI, opts)
end

.Max(objective_expression) ⇒ Object


59
60
61
62
# File 'lib/rulp/rulp.rb', line 59

def self.Max(objective_expression)
  Rulp.log(Logger::INFO, "Creating maximization problem")
  Problem.new(Rulp::MAX, objective_expression)
end

.Min(objective_expression) ⇒ Object


64
65
66
67
# File 'lib/rulp/rulp.rb', line 64

def self.Min(objective_expression)
  Rulp.log(Logger::INFO, "Creating minimization problem")
  Problem.new(Rulp::MIN, objective_expression)
end

.Scip(lp, opts = {}) ⇒ Object


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

def self.Scip(lp, opts={})
  lp.solve_with(SCIP, opts)
end

.solver_exists?(solver_name) ⇒ Boolean

Returns:

  • (Boolean)

69
70
71
72
73
# File 'lib/rulp/rulp.rb', line 69

def self.solver_exists?(solver_name)
  solver = solver_name[0].upcase + solver_name[1..-1].downcase
  solver_class = ObjectSpace.const_defined?(solver) && ObjectSpace.const_get(solver)
  solver_class.exists? if(solver_class)
end