<html><body>
<p><tt><br>
>>I am a beginner regarding CLP, and I would like to ask you whether CLP can be called from a C program. If so, is there some documentation that explains how to do that?</tt><br>
<br>
<tt> Hi,</tt><br>
<br>
<tt>Do you mean exactly C, not C++? For C I do not know the answer (the chances are it may not be possible because COIN it written in C++). For C++ please see below. CLP documentation starts with a simple example which shows how to solve problem from a file. I would also put a reference to file </tt><tt><b>Clp-1.10.0/Clp/examples/addRows.cpp</b></tt><tt> (or similar) to the front page of CLP doc. It shows how to create and solve CLP problem in memory. Please find two examples below. #1 follows CLP doc. #2 follows what John Forrest sent me over lately. The second one worked much better for me. ( Also to be able to "make" your program, first follow the instructions in </tt><tt><b>Clp-1.10.0/</b></tt><tt><b>INSTALL</b></tt><tt>).</tt><br>
<br>
----------------------------------------------------<br>
Dr. Alexey Lvov<br>
IBM T.J. Watson Research Institute<br>
1101 Kitchawan Rd. (Rt. 134) Office 34-159<br>
Yorktown Heights NY 10598<br>
Tel: (914)-945-3732.<br>
<br>
<br>
<br>
<br>
<br>
<tt>1) (a piece from </tt><tt>Clp-1.10.0/Clp/examples</tt><tt>/addRows.cpp )</tt><br>
<br>
<tt>// make DRIVER=NNN makes file NNN.cpp //</tt><br>
<br>
<tt>#include "ClpSimplex.hpp"</tt><br>
<tt>#include "ClpPrimalColumnSteepest.hpp"</tt><br>
<tt>#include "ClpDualRowSteepest.hpp"</tt><br>
<br>
<br>
<br>
<tt>int main ()</tt><br>
<tt>{</tt><br>
<tt> // Minimize x0 + 2 * x1 + 4 * x2 + 5 * x3,</tt><br>
<tt> //</tt><br>
<tt> // 0 <= x0 <= 15,</tt><br>
<tt> // 0 <= x1 ,</tt><br>
<tt> // x2 is not bound by any constraints,</tt><br>
<tt> // -1 <= x3 ,</tt><br>
<tt> //</tt><br>
<tt> // x0 - x2 <= 3,</tt><br>
<tt> //</tt><br>
<tt> // x0 + x1 + x2 + x3 = 23.</tt><br>
<br>
<br>
<br>
<tt> // --- BEGIN add the objective function and bounds on individual var. --- //</tt><br>
<br>
<tt> const int num_variables = 4;</tt><br>
<br>
<tt> ClpSimplex model;</tt><br>
<tt> model.resize(0,num_variables); // The first argument must be 0.</tt><br>
<br>
<tt> model.setObjectiveCoefficient(0, 1.0);</tt><br>
<tt> // Lower bounds for variables are 0.0 by default.</tt><br>
<tt> model.setColumnUpper( 0, 15.0);</tt><br>
<br>
<tt> model.setObjectiveCoefficient(1, 2.0);</tt><br>
<tt> // Lower bounds for variables are 0.0 by default</tt><br>
<tt> model.setColumnUpper( 1, COIN_DBL_MAX);</tt><br>
<br>
<tt> model.setObjectiveCoefficient(2, 4.0);</tt><br>
<tt> model.setColumnLower( 2, -COIN_DBL_MAX);</tt><br>
<tt> model.setColumnUpper( 2, COIN_DBL_MAX);</tt><br>
<br>
<tt> model.setObjectiveCoefficient(3, 5.0);</tt><br>
<tt> model.setColumnLower( 3, -1.0);</tt><br>
<tt> model.setColumnUpper( 3, COIN_DBL_MAX);</tt><br>
<br>
<tt> // --- END add the objective function and bounds on individual var. --- //</tt><br>
<br>
<br>
<tt> // -- BEGIN add equality and ineq. constr. on lin. combinations of var. -- //</tt><br>
<br>
<tt> int * rowIndex;</tt><br>
<tt> double * rowValue;</tt><br>
<tt> int num_nonzero_coef;</tt><br>
<br>
<tt> num_nonzero_coef = 2;</tt><br>
<tt> rowIndex = new int [num_nonzero_coef];</tt><br>
<tt> rowValue = new double[num_nonzero_coef];</tt><br>
<tt> rowIndex[0] = 0; rowValue[0] = 1.0;</tt><br>
<tt> rowIndex[1] = 2; rowValue[1] = -1.0;</tt><br>
<tt> // The 4-th argument is the lower bound,</tt><br>
<tt> // The 5-th argument is the upper bound.</tt><br>
<tt> model.addRow(num_nonzero_coef, rowIndex, rowValue, -COIN_DBL_MAX, 3.0);</tt><br>
<tt> delete[] rowValue;</tt><br>
<tt> delete[] rowIndex;</tt><br>
<br>
<tt> num_nonzero_coef = 4;</tt><br>
<tt> rowIndex = new int [num_nonzero_coef];</tt><br>
<tt> rowValue = new double[num_nonzero_coef];</tt><br>
<tt> rowIndex[0] = 0; rowValue[0] = 1.0;</tt><br>
<tt> rowIndex[1] = 1; rowValue[1] = 1.0;</tt><br>
<tt> rowIndex[2] = 2; rowValue[2] = 1.0;</tt><br>
<tt> rowIndex[3] = 3; rowValue[3] = 1.0;</tt><br>
<tt> // The standard way of adding an equality constraint is to set both</tt><br>
<tt> // the lower and upper bound to the same value.</tt><br>
<tt> model.addRow(num_nonzero_coef, rowIndex, rowValue, 23.0, 23.0);</tt><br>
<tt> delete[] rowValue;</tt><br>
<tt> delete[] rowIndex;</tt><br>
<br>
<tt> // -- END add equality and ineq. constr. on lin. combinations of var. -- //</tt><br>
<br>
<br>
<br>
<tt> // Increase level of detail</tt><br>
<tt> model.setLogLevel(4);</tt><br>
<br>
<tt> // The model has been set up. Now solve!</tt><br>
<tt> model.primal();</tt><br>
<br>
<br>
<br>
<tt> char const * const status_message[5] = {</tt><br>
<tt> "optimal",</tt><br>
<tt> "primal infeasible",</tt><br>
<tt> "primal unbounded, dual infeasible",</tt><br>
<tt> "stopped on iterations etc",</tt><br>
<tt> "stopped due to errors"};</tt><br>
<tt> std::cout << "Model status is \""</tt><br>
<tt> << status_message[model.status()] << "\" after "</tt><br>
<tt> << model.numberIterations() << " iterations - objective is "</tt><br>
<tt> << model.objectiveValue() << std::endl;</tt><br>
<br>
<tt> std::cout << "The model has " << model.numberRows()</tt><br>
<tt> << " rows and " << model.numberColumns()</tt><br>
<tt> << " variables." << std::endl;</tt><br>
<br>
<tt> if (num_variables != model.numberColumns()) {</tt><br>
<tt> std::cout << "ERROR : num_variables != model.numberColumns() .\n";</tt><br>
<tt> return -1;</tt><br>
<tt> }</tt><br>
<br>
<tt> double * columnPrimal = model.primalColumnSolution();</tt><br>
<tt> int iColumn;</tt><br>
<tt> printf("Solution:\n");</tt><br>
<tt> for (iColumn = 0; iColumn < num_variables; iColumn++)</tt><br>
<tt> printf("x%d = %8.5f\n", iColumn, columnPrimal[iColumn]);</tt><br>
<br>
<br>
<br>
<tt> return 0;</tt><br>
<tt>}</tt><br>
<br>
<br>
<br>
<br>
<br>
<tt>2) </tt><br>
<br>
<tt>#include "ClpSimplex.hpp"</tt><br>
<tt>#include "ClpSolve.hpp"</tt><br>
<tt>#include "CoinModel.hpp"</tt><br>
<br>
<tt>.......</tt><br>
<tt>..........</tt><br>
<tt> ClpSimplex * model = new ClpSimplex;</tt><br>
<tt> model->resize(0, lp_num_variables); // The first argument must be 0.</tt><br>
<br>
<tt> for (i = 0; i < lp_num_variables; i++) {</tt><br>
<tt> model->setObjectiveCoefficient(i, lp_objective_function[i]);</tt><br>
<tt> model->setColumnLower(i, (i < lp_num_s_variables) ? 0.0 : -COIN_DBL_MAX);</tt><br>
<tt> model->setColumnUpper(i, COIN_DBL_MAX);</tt><br>
<tt> }</tt><br>
<br>
<tt> {</tt><br>
<tt> // use {} so model2 will vanish</tt><br>
<tt> CoinModel model2;</tt><br>
<tt> for (i = 0; i < lp_num_constr_on_s; i++) { // equality constraints</tt><br>
<tt> model2.addRow(lp_constraints[i].num_coefficients,</tt><br>
<tt> lp_constraints[i].indexes,</tt><br>
<tt> lp_constraints[i].coefficients,</tt><br>
<tt> lp_constraints[i].right_part,</tt><br>
<tt> lp_constraints[i].right_part);</tt><br>
<tt> }</tt><br>
<tt> for ( ; i < lp_num_constraints; i++) { // inequality constraints</tt><br>
<tt> model2.addRow(lp_constraints[i].num_coefficients,</tt><br>
<tt> lp_constraints[i].indexes,</tt><br>
<tt> lp_constraints[i].coefficients,</tt><br>
<tt> lp_constraints[i].right_part,</tt><br>
<tt> COIN_DBL_MAX);</tt><br>
<tt> }</tt><br>
<tt> model->addRows(model2,false);</tt><br>
<tt> }</tt><br>
<tt> </tt><br>
<tt> model->setLogLevel(1);</tt><br>
<tt> ClpSolve solveOptions;</tt><br>
<tt> model->setPerturbation(50);</tt><br>
<tt> model->initialSolve(solveOptions);</tt><br>
<tt>........... </tt><br>
..........<br>
<br>
<br>
</body></html>