Module: Rulp

Defined in:
lib/helpers/log.rb,
lib/rulp/rulp.rb,
lib/rulp/rulp_bounds.rb,
lib/rulp/rulp_initializers.rb

Overview

Basic logger module. Allows logging in the format

“This is a string”.log(:debug) “Oh no!”.log(:error)

Log level is set as follows. Rulp::Logger::level = :debug

Defined Under Namespace

Modules: Bounds, Initializers, Logger 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,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#expressionsObject

Returns the value of attribute expressions.



20
21
22
# File 'lib/rulp/rulp.rb', line 20

def expressions
  @expressions
end

Class Method Details

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



40
41
42
# File 'lib/rulp/rulp.rb', line 40

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

.exec(command) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/rulp/rulp.rb', line 69

def self.exec(command)
  result = ""
  Open3.popen2e("#{command} #{Rulp::Logger.print_solver_outputs ? "" : "> /dev/null 2>&1"}") do | inp, out, thr|
    out.each do |line|
      puts line
      result << line
    end
  end
  return result
end

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



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

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

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



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

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

.Max(objective_expression) ⇒ Object



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

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

.Min(objective_expression) ⇒ Object



57
58
59
60
# File 'lib/rulp/rulp.rb', line 57

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

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



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

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

.solver_exists?(solver_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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