CPLEX 求解过程详解,精简版

/* Bring in the CPLEX function declarations and the C library
   header file stdio.h with the include of cplex.h. */

#include 

/* Bring in the declarations for the string functions */

#include 
#include 

setproblemdata (char *probname_p, int *numcols_p, int *numrows_p,int *objsen_p, double *obj_p, double *rhs_p,
				char *sense_p, int *matbeg_p, int *matcnt_p,int *matind_p, double *matval_p,
				double *lb_p, double *ub_p, char *ctype_p
				);

void main()
{
	/* Declare pointers for the variables and arrays that will contain
   the data which define the LP problem.  The setproblemdata() routine
   allocates space for the problem data.  */
   //定义变量
   char     *probname = NULL;
   int      numcols;
   int      numrows;
   int      objsen;
   double   *obj = NULL;
   double   *rhs = NULL;
   char     *sense = NULL;
   int      *matbeg = NULL;
   int      *matcnt = NULL;
   int      *matind = NULL;
   double   *matval = NULL;
   double   *lb = NULL;
   double   *ub = NULL;
   char     *ctype = NULL;

   CPXENVptr     env = NULL;
   CPXLPptr      lp = NULL;
   int           status;
   int           i, j;
   int           cur_numrows;
   int           cur_numcols;

   //初始化环境变量
   env = CPXopenCPLEX(&status);
   //显示信息到屏幕上面
   status = CPXsetintparam(env,CPX_PARAM,CPX_ON);
   //调用数据设置函数,构造问题
   setproblemdata(&probname, &numcols, &numrows, &objsen, &obj,
	   &rhs, &sense, &matbeg, &matcnt, &matind, &matval,
	   &lb, &ub, &ctype);
   //创建问题对象
   lp = CPXcreateprob(env,&status,probname);
   //复制相关数值
   status = CPXcopylp (env, lp, numcols, numrows, objsen, obj, rhs,
	   sense, matbeg, matcnt, matind, matval,
	   lb, ub, NULL);
   //复制变量类型 
   status = CPXcopyctype (env, lp, ctype);

   /////////////////////////////////////////////////////////////////////////
   //求解问题
      status = CPXmipopt (env, lp);
    //获取结果
	   solstat = CPXgetstat (env, lp);
	   //目标函数
	      status = CPXgetobjval (env, lp, &objval);
	    //x的值
		  status = CPXgetx (env, lp, x, 0, cur_numcols-1);
}





你可能感兴趣的:(Tools)