class OPL::LinearProgram

Attributes

column_bounds[RW]
constraints[RW]
data[RW]
data_hash[RW]
epsilon[RW]
error_message[RW]
m_index[RW]
matrix[RW]
matrix_solution[RW]
mip_message[RW]
negated_objective_lp[RW]
objective[RW]
original_constraints[RW]
rglpk_object[RW]
rows[RW]
simplex_message[RW]
solution[RW]
solution_type[RW]
solver[RW]
stop_processing[RW]
variable_types[RW]

Public Class Methods

new() click to toggle source
# File lib/opl.rb, line 773
def initialize
        @rows = []
        @data = []
        @epsilon = $default_epsilon
        @matrix_solution = {}
        @stop_processing = false
end

Public Instance Methods

keys() click to toggle source
# File lib/opl.rb, line 769
def keys
        [:objective, :constraints, :rows, :solution, :formatted_constraints, :rglpk_object, :solver, :matrix, :simplex_message, :mip_message, :data]
end
recreate_with_objective_abs(objective) click to toggle source
# File lib/opl.rb, line 811
def recreate_with_objective_abs(objective)
        #in: "abs(x)"
        #out: {:objective => "x1 + x2", :constraints => "x1 * x2 = 0"}
        #this is a really tough problem - first time I am considering
                #abandoning the string parsing approach. Really need to think
                #about how to attack this
        lp_class = self
        helper = OPL::Helper
        variabes = helper.variables(objective, lp_class.new)
        new_objective = ""
        constraints_to_add = []
        #return(self)
end
solution_as_matrix() click to toggle source
# File lib/opl.rb, line 781
def solution_as_matrix
        lp = self
        variables = lp.solution.keys.map do |key|
                key.scan(/[a-z]/)[0] if key.include?("[")
        end.uniq.find_all{|e|!e.nil?}
        matrix_solution = {}
        variables.each do |var|
                elements = lp.solution.keys.find_all{|key|key.include?(var) && key.include?("[")}
                num_dims = elements[0].scan(/\]\[/).size + 1
                dim_limits = []
                indices_value_pairs = []
                [*(0..(num_dims-1))].each do |i|
                        dim_limit = 0
                        elements.each do |e|
                                indices = e.scan(/\[\d+\]/).map{|str|str.scan(/\d+/)[0].to_i}
                                value = lp.solution[e]
                                indices_value_pairs << [indices, value]
                                dim_limit = indices[i] if indices[i] > dim_limit
                        end
                        dim_limits << dim_limit+1
                end
                matrix = [].matrix(dim_limits)
                indices_value_pairs.each do |ivp|
                        matrix.insert_at(ivp[0], ivp[1].to_f)
                end
                matrix_solution[var] = matrix
        end
        return(matrix_solution)
end