long GenModelCplex::ChangeBulkRHS(int count, int* ind, double* vals) { CplexData* d = (CplexData*)solverdata; CPXchgrhs(d->env, d->lp, count, ind, vals); return 0; }
reducemex(double M[], double costs[], double stats[], double ikeep[], double m[], int matbeg[], int matcnt[], int matind[], double matval[], char sense[], int objsen, double lb[], double ub[], int numrows, int numcols, double tol) { CPXENVptr env = NULL; CPXLPptr lp = NULL; int status; char probname[16]; double *pi; double *slack; double *dj; double *obj; int solstat; double objval; double *x; double newval; int *indices; int kc, i; obj = mxCalloc(numcols,sizeof(double)); x = mxCalloc(numcols,sizeof(double)); indices = mxCalloc(numcols,sizeof(int)); pi = mxCalloc(numrows,sizeof(double)); slack = mxCalloc(numrows,sizeof(double)); dj = mxCalloc(numcols,sizeof(double)); /* Initialize the CPLEX environment */ env = CPXopenCPLEX (&status); if ( env == NULL ) { char errmsg[1024]; fprintf (stderr, "Could not open CPLEX environment.\n"); CPXgeterrorstring (env, status, errmsg); fprintf (stderr, "%s", errmsg); goto TERMINATE; } /* Turn off output to the screen */ status = CPXsetintparam (env, CPX_PARAM_SCRIND, CPX_OFF); if ( status ) { fprintf (stderr, "Failure to turn on screen indicator, error %d.\n", status); goto TERMINATE; } /* Turn off pre-processor status = CPXsetintparam (env, CPX_PARAM_PREIND, CPX_OFF); if ( status ) { fprintf (stderr, "Failure to turn off pre-processor, error %d.\n", status); goto TERMINATE; } /* Turn off aggregator status = CPXsetintparam (env, CPX_PARAM_AGGIND, CPX_OFF); if ( status ) { fprintf (stderr, "Failure to turn of aggregator, error %d.\n", status); goto TERMINATE; }*/ /* Create the problem. */ strcpy(probname,"LPnoname"); lp = CPXcreateprob (env, &status, probname); if ( lp == NULL ) { fprintf (stderr, "Failed to create LP.\n"); goto TERMINATE; } /* Initialize data */ for (kc = 0; kc <= numcols-1; kc++) { indices[kc] = kc; } /* Now copy the problem data into the lp */ status = CPXcopylp (env, lp, numcols, numrows, objsen, obj, m, sense, matbeg, matcnt, matind, matval, lb, ub, NULL); if ( status ) { fprintf (stderr, "Failed to copy problem data.\n"); goto TERMINATE; } /**********MAIN LOOP************/ for(i = 0; i <= numrows-1; i++) { for (kc = 0; kc <= numcols-1; kc++) { obj[kc] = M[i+kc*numrows]; } CPXchgobj(env, lp, numcols, indices, obj); newval = m[i] + 10; CPXchgrhs(env, lp, 1, &i, &newval); /* Optimize the problem and obtain solution. */ status = CPXlpopt (env, lp); /*status = CPX[prim/dual]opt (env, lp);*/ if ( status ) { fprintf (stderr, "Failed to optimize LP.\n"); goto TERMINATE; } status = CPXsolution (env, lp, &solstat, &objval, x, pi, slack, dj); if ( status ) { fprintf (stderr, "Failed to obtain solution.\n"); goto TERMINATE; } ikeep[i] = 0; if (objval > m[i] + tol) /* keep row */ { ikeep[i] = 1; newval = m[i]; CPXchgrhs(env, lp, 1, &i, &newval); } /* Write the output to the screen. */ /* printf ("\nSolution status = %d\n", solstat); printf ("Solution value = %f\n\n", objval); */ costs[i] = objval; stats[i] = solstat; } TERMINATE: /* Free up the problem as allocated by CPXcreateprob, if necessary */ if ( lp != NULL ) { status = CPXfreeprob (env, &lp); if ( status ) { fprintf (stderr, "CPXfreeprob failed, error code %d.\n", status); } } /* Free up the CPLEX environment, if necessary */ if ( env != NULL ) { status = CPXcloseCPLEX (&env); if ( status ) { char errmsg[1024]; fprintf (stderr, "Could not close CPLEX environment.\n"); CPXgeterrorstring (env, status, errmsg); fprintf (stderr, "%s", errmsg); } } }