cagi
cagi

Reputation: 35

Column-wise formulation CPLEX- Adding new constraint sets within columns

I use callable library of C/C++ to code a set partitioning formulation. I use column-like formulation. I have two clusters of constraints.

Whenever I add columns, I use:

for (i = 1; i <= colIdx ; i++) {   //For all columns
   ...
     status = CPXaddcols(env, lp, 1, colNum, obj, cmatbeg, cmatind , cmatval,
        lb, ub, NULL);}

However; colNum, cmatind and constraint senses are different for these two constraint sets. If I use another CPXaddcols for second constraint set, it adds new variables, but I just want to add new rows within given columns.

How can I solve this problem ?

Upvotes: 1

Views: 743

Answers (1)

Ram Narasimhan
Ram Narasimhan

Reputation: 22506

Yes, you can add multiple rows (constraints) to your CPLEX problem with one call to CPXaddcols.

Just make sure that after your call CPXcreateprob and before you call the CPXaddcols above, you have called in the appropriate number of CPXnewrows to inform CPLEX that these constraints are non-zero.

As the CPLEX help states here

CPXaddcols cannot add coefficients in rows that do not already exist (that is, in rows with index greater than the number returned by CPXgetnumrows); 
[...]
The routine CPXnewrows can be used to add empty rows before adding new columns via CPXaddcols. 

Also, just make sure that when you add your variable colNum is actually referring to the number of non-zero values that you are going to be adding in the new column.

This example has instances where each call of CPXaddcols adds the variable to two constraints.

Specifically look closely at this part of the code:

    /* Add flow variables */

   for (j = 0; j < NUMEDGES; j++) {
      ind[0] = orig[j];  /* Flow leaves origin */
      val[0] = -1.0;
      ind[1] = dest[j];  /* Flow arrives at destination */
      val[1] =  1.0;

      name[0] = buffer;
      sprintf(buffer, "x%d%d", orig[j], dest[j]);

      status = CPXaddcols (env, lp, 1, 2, &unitcost[j], &zero, ind, val,
                           NULL, NULL, name);

Hope that helps.

Upvotes: 1

Related Questions