Exemple #1
0
int c_glp_mip_solve(glp_prob *lp, int msg_lev, int br_tech, int bt_tech, int pp_tech,
		     	int fp_heur, int tm_lim, int cuts, double mip_gap, int presolve){
  	glp_iocp iocp;
	glp_mem_limit(10000);
// 	printf ("%d %d %d time\n", msg_lev, br_tech, tm_lim);
	glp_init_iocp(&iocp);
	iocp.msg_lev = msg_lev;
	iocp.br_tech = br_tech;
	iocp.bt_tech = bt_tech;
	iocp.pp_tech = pp_tech;
	//	iocp.fp_heur = fp_heur ? GLP_ON : GLP_OFF;
// 	printf ("fp %d\n", iocp.fp_heur);
	iocp.gmi_cuts = cuts & 1 ? GLP_ON : GLP_OFF;
	iocp.mir_cuts = cuts & 2 ? GLP_ON : GLP_OFF;
	iocp.cov_cuts = cuts & 4 ? GLP_ON : GLP_OFF;
	iocp.clq_cuts = cuts & 8 ? GLP_ON : GLP_OFF;
	iocp.mip_gap = mip_gap;
	iocp.tm_lim = tm_lim;
// 	printf ("%d %d %d time\n", msg_lev, br_tech, tm_lim);
	iocp.presolve = presolve ? GLP_ON : GLP_OFF;
	return glp_intopt(lp, &iocp);
}
Exemple #2
0
static int parse_cmdline(struct csa *csa, int argc, const char *argv[])
{     /* parse command-line parameters */
      int k;
#define p(str) (strcmp(argv[k], str) == 0)
      for (k = 1; k < argc; k++)
      {  if (p("--mps"))
            csa->format = FMT_MPS_DECK;
         else if (p("--freemps"))
            csa->format = FMT_MPS_FILE;
         else if (p("--cpxlp"))
            csa->format = FMT_CPLEX_LP;
         else if (p("--math") || p("-m") || p("--model"))
            csa->format = FMT_MATHPROG;
         else if (p("-d") || p("--data"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No input data file specifed\n");
               return 1;
            }
            if (csa->ndf == DATA_MAX)
            {  xprintf("Too many input data files\n");
               return 1;
            }
            csa->in_data[++(csa->ndf)] = argv[k];
         }
         else if (p("-y") || p("--display"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No display output file specifed\n");
               return 1;
            }
            if (csa->out_dpy != NULL)
            {  xprintf("Only one display output file allowed\n");
               return 1;
            }
            csa->out_dpy = argv[k];
         }
         else if (p("--mincost"))
            csa->format = FMT_MIN_COST;
         else if (p("--maxflow"))
            csa->format = FMT_MAX_FLOW;
         else if (p("--simplex"))
            csa->solution = SOL_BASIC;
         else if (p("--interior"))
            csa->solution = SOL_INTERIOR;
         else if (p("-r") || p("--read"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No input solution file specifed\n");
               return 1;
            }
            if (csa->in_res != NULL)
            {  xprintf("Only one input solution file allowed\n");
               return 1;
            }
            csa->in_res = argv[k];
         }
         else if (p("--min"))
            csa->dir = GLP_MIN;
         else if (p("--max"))
            csa->dir = GLP_MAX;
         else if (p("--scale"))
            csa->scale = 1;
         else if (p("--noscale"))
            csa->scale = 0;
         else if (p("-o") || p("--output"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No output solution file specified\n");
               return 1;
            }
            if (csa->out_sol != NULL)
            {  xprintf("Only one output solution file allowed\n");
               return 1;
            }
            csa->out_sol = argv[k];
         }
         else if (p("-w") || p("--write"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No output solution file specifed\n");
               return 1;
            }
            if (csa->out_res != NULL)
            {  xprintf("Only one output solution file allowed\n");
               return 1;
            }
            csa->out_res = argv[k];
         }
         else if (p("--bounds"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No sensitivity bounds output file specified\n");
               return 1;
            }
            if (csa->out_bnds != NULL)
            {  xprintf("Only one sensitivity bounds output file allowed"
                  "\n");
               return 1;
            }
            csa->out_bnds = argv[k];
         }
         else if (p("--tmlim"))
         {  int tm_lim;
            k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No time limit specified\n");
               return 1;
            }
            if (str2int(argv[k], &tm_lim) || tm_lim < 0)
            {  xprintf("Invalid time limit `%s'\n", argv[k]);
               return 1;
            }
            if (tm_lim <= INT_MAX / 1000)
               csa->smcp.tm_lim = csa->iocp.tm_lim = 1000 * tm_lim;
            else
               csa->smcp.tm_lim = csa->iocp.tm_lim = INT_MAX;
         }
         else if (p("--memlim"))
         {  int mem_lim;
            k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No memory limit specified\n");
               return 1;
            }
            if (str2int(argv[k], &mem_lim) || mem_lim < 1)
            {  xprintf("Invalid memory limit `%s'\n", argv[k]);
               return 1;
            }
            glp_mem_limit(mem_lim);
         }
         else if (p("--check"))
            csa->check = 1;
         else if (p("--name"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No problem name specified\n");
               return 1;
            }
            if (csa->new_name != NULL)
            {  xprintf("Only one problem name allowed\n");
               return 1;
            }
            csa->new_name = argv[k];
         }
         else if (p("--wmps"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No fixed MPS output file specified\n");
               return 1;
            }
            if (csa->out_mps != NULL)
            {  xprintf("Only one fixed MPS output file allowed\n");
               return 1;
            }
            csa->out_mps = argv[k];
         }
         else if (p("--wfreemps"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No free MPS output file specified\n");
               return 1;
            }
            if (csa->out_freemps != NULL)
            {  xprintf("Only one free MPS output file allowed\n");
               return 1;
            }
            csa->out_freemps = argv[k];
         }
         else if (p("--wcpxlp") || p("--wlpt"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No CPLEX LP output file specified\n");
               return 1;
            }
            if (csa->out_cpxlp != NULL)
            {  xprintf("Only one CPLEX LP output file allowed\n");
               return 1;
            }
            csa->out_cpxlp = argv[k];
         }
         else if (p("--wpb"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No problem output file specified\n");
               return 1;
            }
            if (csa->out_pb != NULL)
            {  xprintf("Only one OPB output file allowed\n");
               return 1;
            }
            csa->out_pb = argv[k];
         }
         else if (p("--wnpb"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No problem output file specified\n");
               return 1;
            }
            if (csa->out_npb != NULL)
            {  xprintf("Only one normalized OPB output file allowed\n");
               return 1;
            }
            csa->out_npb = argv[k];
         }
         else if (p("--log"))
         {  k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No log file specified\n");
               return 1;
            }
            if (csa->log_file != NULL)
            {  xprintf("Only one log file allowed\n");
               return 1;
            }
            csa->log_file = argv[k];
         }
         else if (p("-h") || p("--help"))
         {  print_help(argv[0]);
            return -1;
         }
         else if (p("-v") || p("--version"))
         {  print_version();
            return -1;
         }
         else if (p("--luf"))
            csa->bfcp.type = GLP_BF_FT;
         else if (p("--cbg"))
            csa->bfcp.type = GLP_BF_BG;
         else if (p("--cgr"))
            csa->bfcp.type = GLP_BF_GR;
         else if (p("--primal"))
            csa->smcp.meth = GLP_PRIMAL;
         else if (p("--dual"))
            csa->smcp.meth = GLP_DUAL;
         else if (p("--std"))
            csa->crash = USE_STD_BASIS;
         else if (p("--adv"))
            csa->crash = USE_ADV_BASIS;
         else if (p("--bib"))
            csa->crash = USE_CPX_BASIS;
         else if (p("--steep"))
            csa->smcp.pricing = GLP_PT_PSE;
         else if (p("--nosteep"))
            csa->smcp.pricing = GLP_PT_STD;
         else if (p("--relax"))
            csa->smcp.r_test = GLP_RT_HAR;
         else if (p("--norelax"))
            csa->smcp.r_test = GLP_RT_STD;
         else if (p("--presol"))
            csa->smcp.presolve = GLP_ON;
         else if (p("--nopresol"))
            csa->smcp.presolve = GLP_OFF;
         else if (p("--exact"))
            csa->exact = 1;
         else if (p("--xcheck"))
            csa->xcheck = 1;
         else if (p("--nomip"))
            csa->nomip = 1;
         else if (p("--first"))
            csa->iocp.br_tech = GLP_BR_FFV;
         else if (p("--last"))
            csa->iocp.br_tech = GLP_BR_LFV;
         else if (p("--drtom"))
            csa->iocp.br_tech = GLP_BR_DTH;
         else if (p("--mostf"))
            csa->iocp.br_tech = GLP_BR_MFV;
         else if (p("--pcost"))
            csa->iocp.br_tech = GLP_BR_HPC;
         else if (p("--dfs"))
            csa->iocp.bt_tech = GLP_BT_DFS;
         else if (p("--bfs"))
            csa->iocp.bt_tech = GLP_BT_BFS;
         else if (p("--bestp"))
            csa->iocp.bt_tech = GLP_BT_BPH;
         else if (p("--bestb"))
            csa->iocp.bt_tech = GLP_BT_BLB;
         else if (p("--intopt"))
            csa->iocp.presolve = GLP_ON;
         else if (p("--nointopt"))
            csa->iocp.presolve = GLP_OFF;
         else if (p("--binarize"))
            csa->iocp.presolve = csa->iocp.binarize = GLP_ON;
         else if (p("--gomory"))
            csa->iocp.gmi_cuts = GLP_ON;
         else if (p("--mir"))
            csa->iocp.mir_cuts = GLP_ON;
         else if (p("--cover"))
            csa->iocp.cov_cuts = GLP_ON;
         else if (p("--clique"))
            csa->iocp.clq_cuts = GLP_ON;
         else if (p("--cuts"))
            csa->iocp.gmi_cuts = csa->iocp.mir_cuts =
            csa->iocp.cov_cuts = csa->iocp.clq_cuts = GLP_ON;
         else if (p("--mipgap"))
         {  double mip_gap;
            k++;
            if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-')
            {  xprintf("No relative gap tolerance specified\n");
               return 1;
            }
            if (str2num(argv[k], &mip_gap) || mip_gap < 0.0)
            {  xprintf("Invalid relative mip gap tolerance `%s'\n",
                  argv[k]);
               return 1;
            }
            csa->iocp.mip_gap = mip_gap;
         }
         else if (argv[k][0] == '-' ||
                 (argv[k][0] == '-' && argv[k][1] == '-'))
         {  xprintf("Invalid option `%s'; try %s --help\n",
               argv[k], argv[0]);
            return 1;
         }
         else
         {  if (csa->in_file != NULL)
            {  xprintf("Only one input problem file allowed\n");
               return 1;
            }
            csa->in_file = argv[k];
         }
      }
#undef p
      return 0;
}