Originally posted by: ChiaWeng
Thank you all for the replies. The 'network' was not supposed to show up. I modified an example and forgot to change it in the printf command. My full code is shown below using version Academic version 12.3 together with the output from CPXwriteparam(). My suspicion is that the SIMPLEX was used to get the answer(feasible starting point) and the barrier method was not used at all since the problem formulation was meaningless. But I hope there would be a way to force the barrier method to accept the original formulation and proceed with the iteration.
#include <ilcplex/cplex.h>
#include <stdio.h>
#include <stdlib.h>
#define COLSORIG 3
#define ROWSSUB 6
#define NZSUB (2*COLSORIG)
#define ROWSCOMP 0
#define NZCOMP (ROWSCOMP*COLSORIG)
#define ROWSTOT (ROWSSUB+ROWSCOMP)
#define NZTOT (NZCOMP+NZSUB)
int
main()
{
/* Data for original problem. Arrays have to be big enough to hold
problem plus additional constraints. */
double Hrhs
ROWSTOT = { 2, 2, 2, 2, 2,2};
double Hlb
COLSORIG = { -CPX_INFBOUND, -CPX_INFBOUND, -CPX_INFBOUND};
double Hub
COLSORIG = { CPX_INFBOUND, CPX_INFBOUND, CPX_INFBOUND};
double Hcost
COLSORIG = { 0.0000000000000000, 0.0000000000000000, 0.0000000000000000};
char Hsense
ROWSTOT = { 'L', 'L', 'L', 'L', 'L', 'L'};
int Hmatbeg
COLSORIG = { 0, 2, 4};
int Hmatcnt
COLSORIG = { 2, 2, 2};
int Hmatind
NZTOT = { 0, 1, 2, 3, 4, 5};
double Hmatval
NZTOT = { 1.0, -1.0, 1.0, -1.0, 1.0, -1.0};
double x
COLSORIG; x[0]=1.0; x[1]=0.0; x[2]=0.0;
CPXENVptr env = NULL;
CPXLPptr lp = NULL;
int j;
int status, lpstat;
double objval;
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;
}
status = CPXsetintparam (env, CPX_PARAM_SCRIND, CPX_ON);
if ( status ) {
fprintf (stderr,
"Failure to turn on screen indicator, error %d.\n", status);
goto TERMINATE;
}
status = CPXsetintparam (env, CPX_PARAM_BARDISPLAY, 2);
if ( status ) {
fprintf (stderr,"Failed to turn up simplex display level.\n");
goto TERMINATE;
}
/* Create the problem */
lp = CPXcreateprob (env, &status, "chvatal");
if ( lp == NULL ) {
fprintf (stderr,"Failed to create subproblem\n");
status = 1;
goto TERMINATE;
}
status = CPXcopylp (env, lp, COLSORIG, ROWSSUB, CPX_MIN, Hcost, Hrhs,
Hsense, Hmatbeg, Hmatcnt, Hmatind, Hmatval,
Hlb, Hub, NULL);
if ( status ) {
fprintf (stderr, "CPXcopylp failed.\n");
goto TERMINATE;
}
status = CPXsetintparam (env, CPX_PARAM_THREADS, 1);
status = CPXsetintparam (env, CPX_PARAM_PREIND, 0);
status = CPXsetintparam (env, CPX_PARAM_LPMETHOD, CPX_ALG_BARRIER);
status = CPXsetintparam (env, CPX_PARAM_BARCROSSALG, CPX_ALG_NONE);
status = CPXsetintparam (env, CPX_PARAM_BARALG, 3);
status = CPXsetdblparam (env, CPX_PARAM_BAREPCOMP, 1.0e-8);
status = CPXsetintparam (env, CPX_PARAM_DEPIND, 0);
status = CPXsetintparam (env, CPX_PARAM_REDUCE, 0);
status = CPXsetintparam (env, CPX_PARAM_SYMMETRY, 0);
status = CPXsetintparam (env, CPX_PARAM_AGGIND, 0);
status = CPXsetintparam (env, CPX_PARAM_COEREDIND, 0);
status = CPXsetintparam (env, CPX_PARAM_PRELINEAR, 0);
status = CPXsetintparam (env, CPX_PARAM_PREPASS, 0);
status = CPXsetintparam (env, CPX_PARAM_PRESLVND, 0);
status = CPXsetintparam (env, CPX_PARAM_PREDUAL, -1);
status = CPXsetintparam (env, CPX_PARAM_PREIND, 0);
status = CPXsetintparam (env, CPX_PARAM_RELAXPREIND, 0);
status = CPXsetintparam (env, CPX_PARAM_REPEATPRESOLVE, 0);
status = CPXwriteparam (env, "analyticCenter.prm");
if ( status ) {
fprintf (stderr,
"Failed to set the optimization method, error %d.\n", status);
goto TERMINATE;
}
status = CPXlpopt (env, lp);
if ( status ) {
fprintf (stderr, "Failed to optimize LP.\n");
goto TERMINATE;
}
status = CPXgetobjval (env, lp, &objval);
if ( status ) {
fprintf (stderr,"CPXgetobjval failed\n");
goto TERMINATE;
}
printf ("After barrier optimization, objective is %.10g\n", objval);
status = CPXsolution (env, lp, &lpstat, &objval, x, NULL, NULL, NULL);
if ( status ) {
fprintf (stderr,"CPXsolution failed.\n");
goto TERMINATE;
}
printf ("Solution status %d\n",lpstat);
printf ("Objective value %g\n",objval);
printf ("Solution is:\n");
for (j = 0; j < COLSORIG; j++) {
printf ("x
%d = %g\n",j,x[j]);
}
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);
/* Note that CPXcloseCPLEX produces no output,
so the only way to see the cause of the error is to use
CPXgeterrorstring. For other CPLEX routines, the errors will
be seen if the CPX_PARAM_SCRIND indicator is set to CPX_ON. */
if ( status ) {
char errmsg
1024;
fprintf (stderr, "Could not close CPLEX environment.\n");
CPXgeterrorstring (env, status, errmsg);
fprintf (stderr, "%s", errmsg);
}
}
return (status);
} /* END main */
___________________________________________________________
IBM ILOG License Manager: "IBM ILOG Optimization Suite for Academic Initiative" is accessing CPLEX 12 with option(s): "e m b q ".
Tried aggregator 0 times.
Presolve time = 0.00 sec.
Tried aggregator 0 times.
LP Presolve eliminated 6 rows and 3 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec.
Total time on 1 threads = 0.00 sec.
Total time on 1 threads = 0.00 sec.
After barrier optimization, objective is 0
Solution status 1
Objective value 0
Solution is:
x[0] = -2
x[1] = -2
x[2] = -2
Expected answer from barrier should be (0,0,0).
___________________________________________________________________________________
CPLEX Parameter File Version 12.3.0.0
CPX_PARAM_AGGIND 0
CPX_PARAM_DEPIND 0
CPX_PARAM_PREIND 0
CPX_PARAM_SCRIND 1
CPX_PARAM_PREDUAL -1
CPX_PARAM_PREPASS 0
CPX_PARAM_REDUCE 0
CPX_PARAM_PRELINEAR 0
CPX_PARAM_LPMETHOD 4
CPX_PARAM_THREADS 1
CPX_PARAM_COEREDIND 0
CPX_PARAM_RELAXPREIND 0
CPX_PARAM_SYMMETRY 0
CPX_PARAM_REPEATPRESOLVE 0
CPX_PARAM_BARALG 3
CPX_PARAM_BARDISPLAY 2
CPX_PARAM_BARCROSSALG -1
Yours,
Boon
#CPLEXOptimizers#DecisionOptimization