Understanding Clp_addColumns from Clp_C_Interface.h #179
Replies: 2 comments 8 replies
-
Andrea,
elements normally only has non-zero values.
rows is used to indicate the row number of the corresponding value in
elements.
When more than one column is being added, then the index into elements of
where each column starts is stored in columnStarts.
So, if you are adding a column with nonzero elements of 3 in row 4 and -6
in row 8, then you could define columnStarts, rows, and elements as:
```
double elements[2] = {3.0, -6.0};
int rows[2] = {4, 8};
int columnStarts[2] = {0,2};
// note: the number of elements in the i’th column is
(columnStarts[i+1]-columnStarts[i])
// the number of elements in columnStarts will be one more than the number
of columns being added
```
I hope this helps (and is correct).
JP
…On Tue, Mar 16, 2021 at 5:36 AM Andrea Gavana ***@***.***> wrote:
Dear CLP Community,
this is my first message here and I am a very new user of CLP, so I
apologize in advance for my ignorant questions. I would also like to
mention that my proficiency in C++ is close to zero.
I am trying to build a model in CLP (and I can only use the
Clp_C_Interface for this). I first tried with Clp_loadProblem and, while it
works, it appears I can do better using Clp_addColumns. But I can't
understand what the two parameters columnStarts and rows are supposed to
contain. This is the signature of Clp_addColumns:
CLPLIB_EXPORT void CLP_LINKAGE Clp_addColumns(Clp_Simplex *model, int number, const double *columnLower,
const double *columnUpper,
const double *objective,
const CoinBigIndex *columnStarts, const int *rows,
const double *elements);
Assuming I have a model with 20 rows (constraints) and 15 columns
(variables) and I want to add *one column at the time* using
Clp_addColumns, I understand that the parameters *columnLower*,
*columnUpper* and *objective* are of size 1 (1 element only, as it's one
column at the time). The *elements* parameter should have 20 elements
(rows per column). But I am at complete loss when it comes to
*columnStarts* and *rows* parameters,
I have consulted the help page for Clp_addColumns and also for addColumns,
but I can't figure out how to proceed.
As a side note, I have looked at the simple example in this issue: #113
<#113>, and I am building the model
in the same way:
Clp_Simplex *mod = Clp_newModel();Clp_resize(mod, m, 0);
Thank you in advance for any suggestions.
Andrea.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#179>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJMOGOKNQB3J6EDVC7OV43TD4RDNANCNFSM4ZIF2PZQ>
.
|
Beta Was this translation helpful? Give feedback.
-
Hi @tkralphs , @jhmgoossens , thank you for your answers. First of all, I would like to say that debugging the COIN code is way above my capabilities - my knowledge of C++ is minuscule at best, and the COIN code is very mature and long. I will never get out of that maze with some meaningful conclusions. That said, I have done a few more tests. To address @jhmgoossens question, this is the only line I am timing in Cython: start = time.clock()
Clp_loadProblem(self._model, n, m,
&col_starts[0], &row_indices[0], &constraints_matrix[0, 0],
&col_lb[0], &col_ub[0], &obj[0], &row_lb[0], &row_ub[0])
end = time.clock()
print(end - start) As you can see, everything is passed by reference. I can't imagine there being any copying/marshalling of data as that call is pretty much a straight C-invocation into the COIN C interface. Timing the executable loading time and the Again, please note that the scale is logarithmic. What this tells me is that, whatever I have no idea on how to implement a version of |
Beta Was this translation helpful? Give feedback.
-
Dear CLP Community,
this is my first message here and I am a very new user of CLP, so I apologize in advance for my ignorant questions. I would also like to mention that my proficiency in C++ is close to zero.
I am trying to build a model in CLP (and I can only use the Clp_C_Interface for this). I first tried with Clp_loadProblem and, while it works, it appears I can do better using Clp_addColumns. But I can't understand what the two parameters columnStarts and rows are supposed to contain. This is the signature of Clp_addColumns:
Assuming I have a model with 20 rows (constraints) and 15 columns (variables) and I want to add one column at the time using Clp_addColumns, I understand that the parameters columnLower, columnUpper and objective are of size 1 (1 element only, as it's one column at the time). The elements parameter should have 20 elements (rows per column). But I am at complete loss when it comes to columnStarts and rows parameters,
I have consulted the help page for Clp_addColumns and also for addColumns, but I can't figure out how to proceed.
As a side note, I have looked at the simple example in this issue: #113, and I am building the model in the same way:
Thank you in advance for any suggestions.
Andrea.
Beta Was this translation helpful? Give feedback.
All reactions