Class: Clp::Model
- Inherits:
-
Object
- Object
- Clp::Model
- Defined in:
- lib/clp/model.rb
Instance Method Summary collapse
-
#initialize ⇒ Model
constructor
A new instance of Model.
- #load_problem(sense:, start:, index:, value:, col_lower:, col_upper:, obj:, row_lower:, row_upper:, offset: 0) ⇒ Object
- #read_mps(filename) ⇒ Object
- #solve(log_level: nil, time_limit: nil) ⇒ Object
- #write_mps(filename) ⇒ Object
Constructor Details
Instance Method Details
#load_problem(sense:, start:, index:, value:, col_lower:, col_upper:, obj:, row_lower:, row_upper:, offset: 0) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/clp/model.rb', line 10 def load_problem(sense:, start:, index:, value:, col_lower:, col_upper:, obj:, row_lower:, row_upper:, offset: 0) start_size = start.size index_size = index.size num_cols = col_lower.size num_rows = row_lower.size FFI.Clp_loadProblem( model, num_cols, num_rows, big_index_array(start, start_size), int_array(index, index_size), double_array(value, index_size), double_array(col_lower, num_cols), double_array(col_upper, num_cols), double_array(obj, num_cols), double_array(row_lower, num_rows), double_array(row_upper, num_rows) ) FFI.Clp_setObjSense(model, FFI::OBJ_SENSE.fetch(sense)) FFI.Clp_setObjectiveOffset(model, offset) end |
#read_mps(filename) ⇒ Object
26 27 28 |
# File 'lib/clp/model.rb', line 26 def read_mps(filename) check_status FFI.Clp_readMps(model, filename, 0, 0) end |
#solve(log_level: nil, time_limit: nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/clp/model.rb', line 37 def solve(log_level: nil, time_limit: nil) (log_level: log_level, time_limit: time_limit) do # do not check status FFI.Clp_initialSolve(model) end num_rows = FFI.Clp_numberRows(model) num_cols = FFI.Clp_numberColumns(model) { status: FFI::STATUS[FFI.Clp_status(model)], objective: FFI.Clp_objectiveValue(model), primal_row: read_double_array(FFI.Clp_primalRowSolution(model), num_rows), primal_col: read_double_array(FFI.Clp_primalColumnSolution(model), num_cols), dual_row: read_double_array(FFI.Clp_dualRowSolution(model), num_rows), dual_col: read_double_array(FFI.Clp_dualColumnSolution(model), num_cols) } end |