struct lpResult * lpFunc(double *b, double **A, double *obj, char *vtype, int m, int n, char *conType, int reportBasis, struct lpResult *output)
Basically, I needed a function in which if I passed a constraint matrix, objective function, RHS, variable types and constraint types, I could retrieve the solution and objective value (in the struct).
I believe that the lines important to this question are:
GRBenv *env = malloc(sizeof(double)*10000);//NULL; //create gurobi environment
GRBmodel *model = NULL; //create model variable
int error = 0;
error = GRBloadenv(&env, "");
if (error || env == NULL) {
fprintf(stderr, "Error: could not create environment\n");
exit(1);
}
/* Create an empty model */
error = GRBnewmodel(env, &model, "CG_Proc", 0, NULL, NULL, NULL, NULL, NULL);
if (error) goto QUIT;
error = GRBsetintparam(GRBgetenv(model), GRB_INT_PAR_OUTPUTFLAG, 0);
if (error) goto QUIT;
/* Add variables */
error = GRBaddvars(model, n, 0, NULL, NULL, NULL, obj, NULL, NULL, vtype, NULL);
//
/* Change objective sense to maximization */
error = GRBsetintattr(model, GRB_INT_ATTR_MODELSENSE, GRB_MAXIMIZE);
if (error) goto QUIT;
/* Integrate new variables */
error = GRBupdatemodel(model);
if (error) goto QUIT; /////WILL NEED TO UNCOMMENT THIS LATER
error = GRBsetintparam(env, "Method", -1);
error = GRBsetintparam(env, "InfUnbdInfo", 1); ///collect ray if unbounded
if (error) goto QUIT;
int row = 0;
////add constraints
for(row = 0; row < m; row++)
{
int *ind = malloc(sizeof(int)*n*2);
double *val = malloc(sizeof(double)*2*n);
int col = 0;
for(col = 0; col < n; col++)
{
ind[col] = col;
val[col] = A[row][col];
}
error = GRBaddconstr(model, n, ind, val, conType[row], b[row], NULL);
free(val); free(ind);
printf("");
if (error) goto QUIT;
}
--
---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.