示例#1
0
        /***********************************************************************
         *  NAME
         *
         *  glp_init_iocp - initialize integer optimizer control parameters
         *
         *  SYNOPSIS
         *
         *  void glp_init_iocp(glp_iocp *parm);
         *
         *  DESCRIPTION
         *
         *  The routine glp_init_iocp initializes control parameters, which are
         *  used by the integer optimizer, with default values.
         *
         *  Default values of the control parameters are stored in a glp_iocp
         *  structure, which the parameter parm points to. */

        void glp_init_iocp(glp_iocp parm)
        {
            parm.msg_lev  = glp_smcp.GLP_MSG_ALL;
            parm.br_tech  = glp_iocp.GLP_BR_DTH;
            parm.bt_tech  = glp_iocp.GLP_BT_BLB;
            parm.tol_int  = 1e-5;
            parm.tol_obj  = 1e-7;
            parm.tm_lim   = Int32.MaxValue;
            parm.out_frq  = 5000;
            parm.out_dly  = 10000;
            parm.cb_func  = null;
            parm.cb_info  = null;
            parm.cb_size  = 0;
            parm.pp_tech  = glp_iocp.GLP_PP_ALL;
            parm.mip_gap  = 0.0;
            parm.mir_cuts = glp_smcp.GLP_OFF;
            parm.gmi_cuts = glp_smcp.GLP_OFF;
            parm.cov_cuts = glp_smcp.GLP_OFF;
            parm.clq_cuts = glp_smcp.GLP_OFF;
            parm.presolve = glp_smcp.GLP_OFF;
            parm.binarize = glp_smcp.GLP_OFF;
            parm.fp_heur  = glp_smcp.GLP_OFF;
            parm.alien    = glp_smcp.GLP_OFF;
            return;
        }
示例#2
0
        public void mipSolve()
        {
            try
            {
                mipReturn = -1;

                /* double ae_max = -1, re_max=-1;
                 * int ae_ind = 0, re_ind = 0;
                 * glp_check_kkt(lp, 2, SolverGLPK.GLP_KKT_DE, ref ae_max, ref ae_ind, ref re_max, ref re_ind);*/
                glp_iocp iocpParm = new glp_iocp();
                glp_init_iocp(iocpParm);
                CallbackDelegate cd  = new CallbackDelegate(callBack);
                IntPtr           ptr = Marshal.GetFunctionPointerForDelegate(cd);
                iocpParm.cb_func = ptr.ToPointer();
                if ((Program.MAXTIME_SIMPLEX - SimplextimeUse) <= 0)
                {
                    iocpParm.tm_lim = 1;
                }
                else
                {
                    iocpParm.tm_lim = (int)Program.MAXTIME_SIMPLEX - SimplextimeUse;
                }
                iocpParm.gmi_cuts = GLP_ON;
                iocpParm.mir_cuts = GLP_ON;
                // iocpParm.tol_int = 0.001;
                //iocpParm.tol_obj = 0.0001;
                //iocpParm.pp_tech = glp_iocp.GLP_PP_ALL;
                iocpParm.presolve = GLP_OFF;
                //iocpParm.mip_gap = 0.01;

                /*
                 * iocpParm.binarize = GLP_ON;
                 * iocpParm.presolve = GLP_ON;*/
                //glp_unscale_prob(lp);

                #region comment : mip return valeur

                /*
                 * glp_intopt : solve MIP problem with the branch-and-cut method
                 *
                 * 0 The MIP problem instance has been successfully solved. (This code does not necessarily mean that the solver has found optimal solution.
                 * It only means that the solution process was successful.)
                 * GLP_EBOUND Unable to start the search, because some double-bounded variables have incorrect bounds or some integer variables have non-integer (fractional) bounds.
                 * GLP_EROOT Unable to start the search, because optimal basis for initial LP relaxation is not provided. (This code may appear only if the presolver is disabled.)
                 * GLP_ENOPFS Unable to start the search, because LP relaxation of the MIP problem instance has no primal feasible solution. (This code may appear only if the presolver is enabled.)
                 * GLP_ENODFS Unable to start the search, because LP relaxation of the MIP problem instance has no dual feasible solution. In other word, this code means that if the LP relaxation has
                 * at least one primal feasible solution, its optimal solution is unbounded, so if the MIP problem has at least one integer feasible solution, its (integer) optimal solution
                 * is also unbounded. (This code may appear only if the presolver is enabled.)
                 * GLP_EFAIL The search was prematurely terminated due to the solver failure.
                 * GLP_EMIPGAP The search was prematurely terminated, because the relative mip gap tolerance has been reached.
                 * GLP_ETMLIM The search was prematurely terminated, because the time limit has been exceeded.
                 * GLP_ESTOP The search was prematurely terminated by application. (This code may appear only if the advanced solver interface is used.)
                 *
                 */

                /**mipStatus :
                 * GLP_UNDEF | MIP solution is undefiened;
                 * GLP_OPT | MIP solution is integer optimal;
                 * GLP_FEAS | MIP solution is integer feasible, however, its optimality (or non-optimality) has
                 * not been proven, perhaps due to premature termination of the search;
                 * GLP_NOFEAS | problem has no integer feasible solution (proven by the solver).
                 *
                 */
                #endregion

                mipReturn = glp_intopt(lp, iocpParm);//return 0 if the MIP problem instance has been successfully solved
                int mipStatus = glp_mip_status(lp);
                glp_mem_usage(null, null, ref memUse, null);

                switch (mipReturn)
                {
                case 0:
                    if (mipStatus == GLP_FEAS)
                    {
                        mipOK = true;
                        //Console.Out.WriteLine("mip : solution réalisable");
                    }
                    else if (mipStatus == GLP_OPT)
                    {
                        mipOK = true;
                        //Console.Out.WriteLine("mip : optimale");
                    }
                    else
                    {
                        mipOK = false;
                        //Console.Out.WriteLine("mip ne peut pas obtenir une solution en nombre entiers réalisable");
                    }
                    break;

                case GLP_ETMLIM:

                    // Console.Out.WriteLine("mip : temps limit dépassée");
                    mipTimeOverflow = true;
                    if (mipStatus == GLP_FEAS)
                    {
                        mipOK = true;
                        //Console.Out.WriteLine("mip : solution réalisable trouvé");
                    }
                    else if (mipStatus == GLP_OPT)
                    {
                        mipOK = true;
                        //Console.Out.WriteLine("mip : optimale");
                    }
                    else
                    {
                        mipOK = false;
                        // Console.Out.WriteLine("mip : pas de solution réalisable");
                    }
                    break;

                case GLP_ESTOP:
                    //Console.Out.WriteLine("mip : memory limit dépassée");
                    if (mipStatus == GLP_FEAS)
                    {
                        mipOK = true;
                        //Console.Out.WriteLine("mip : solution réalisable trouvé");
                    }
                    else if (mipStatus == GLP_OPT)
                    {
                        mipOK = true;
                        //Console.Out.WriteLine("mip : optimale");
                    }
                    else
                    {
                        mipOK = false;
                        //Console.Out.WriteLine("mip : pas de solution réalisable");
                    }
                    break;

                default:
                {
                    mipOK = false;
                    glp_mem_usage(null, null, ref memUse, null);
                    //Console.Out.WriteLine("mip failure");
                    break;
                }
                }
            }

            catch (Exception e)
            {
                throw e;
            }
        }
示例#3
0
 public static extern int glp_intopt(double *P, glp_iocp parm);