Scippy

SCIP

Solving Constraint Integer Programs

cmain.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright 2002-2022 Zuse Institute Berlin */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file GMI/src/cmain.c
26  * @brief main file for GMI cut example
27  * @author Marc Pfetsch
28  */
29 
30 /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #include <scip/scip.h>
33 #include <scip/scipdefplugins.h>
34 #include "sepa_gmi.h"
35 
36 /** reads parameters */
37 static
39  SCIP* scip, /**< SCIP data structure */
40  const char* filename /**< parameter file name, or NULL */
41  )
42 {
43  if ( filename != NULL )
44  {
45  if ( SCIPfileExists(filename) )
46  {
47  SCIPinfoMessage(scip, NULL, "reading parameter file <%s> ...\n", filename);
48  SCIP_CALL( SCIPreadParams(scip, filename) );
49  }
50  else
51  SCIPinfoMessage(scip, NULL, "parameter file <%s> not found - using default parameters.\n", filename);
52  }
53  else if ( SCIPfileExists("scipgmi.set") )
54  {
55  SCIPinfoMessage(scip, NULL, "reading parameter file <scipgmi.set> ...\n");
56  SCIP_CALL( SCIPreadParams(scip, "scipgmi.set") );
57  }
58 
59  return SCIP_OKAY;
60 }
61 
62 /** starts SCIP */
63 static
65  SCIP* scip, /**< SCIP data structure */
66  const char* filename /**< input file name */
67  )
68 {
69  /********************
70  * Problem Creation *
71  ********************/
72 
73  SCIPinfoMessage(scip, NULL, "read problem <%s> ...\n\n", filename);
74  SCIP_CALL( SCIPreadProb(scip, filename, NULL) );
75 
76  /*******************
77  * Problem Solving *
78  *******************/
79 
80  /* solve problem */
81  SCIPinfoMessage(scip, NULL, "solve problem ...\n\n");
82  SCIP_CALL( SCIPsolve(scip) );
83 
84  SCIPinfoMessage(scip, NULL, "primal solution:\n");
86 
87  /**************
88  * Statistics *
89  **************/
90 
91  SCIPinfoMessage(scip, NULL, "Statistics:\n");
93 
94  return SCIP_OKAY;
95 }
96 
97 /** starts user interactive mode */
98 static
100  SCIP* scip /**< SCIP data structure */
101  )
102 {
104 
105  return SCIP_OKAY;
106 }
107 
108 /** creates a SCIP instance with default plugins, evaluates command line parameters, runs SCIP appropriately,
109  * and frees the SCIP instance
110  */
111 static
113  int argc, /**< number of shell parameters */
114  char** argv /**< array with shell parameters */
115  )
116 {
117  SCIP* scip = NULL;
118 
119  /*********
120  * Setup *
121  *********/
122 
123  /* initialize SCIP */
124  SCIP_CALL( SCIPcreate(&scip) );
125 
126  /* we explicitly enable the use of a debug solution for this main SCIP instance */
127  SCIPenableDebugSol(scip);
128 
129  /***********************
130  * Version information *
131  ***********************/
132 
133  SCIPprintVersion(scip, NULL);
134  SCIPinfoMessage(scip, NULL, "\n");
135 
136  /* include default SCIP plugins */
138 
139  /* include GMI cut separator */
140  SCIP_CALL( SCIPincludeSepaGMI(scip) );
141 
142  /**************
143  * Parameters *
144  **************/
145 
146  if ( argc >= 3 )
147  {
148  SCIP_CALL( readParams(scip, argv[2]) );
149  }
150  else
151  {
152  SCIP_CALL( readParams(scip, NULL) );
153  }
154 
155  /**************
156  * Start SCIP *
157  **************/
158 
159  if ( argc >= 2 )
160  {
161  SCIP_CALL( fromCommandLine(scip, argv[1]) );
162  }
163  else
164  {
165  SCIPinfoMessage(scip, NULL, "\n");
166 
167  SCIP_CALL( interactive(scip) );
168  }
169 
170  /********************
171  * Deinitialization *
172  ********************/
173 
174  SCIP_CALL( SCIPfree(&scip) );
175 
177 
178  return SCIP_OKAY;
179 }
180 
181 /** main method starting SCIP */
182 int main(
183  int argc, /**< number of arguments from the shell */
184  char** argv /**< array of shell arguments */
185  )
186 {
187  SCIP_RETCODE retcode;
188 
189  retcode = runSCIP(argc, argv);
190  if ( retcode != SCIP_OKAY )
191  {
192  SCIPprintError(retcode);
193  return -1;
194  }
195 
196  return 0;
197 }
SCIP_RETCODE SCIPprintBestSol(SCIP *scip, FILE *file, SCIP_Bool printzeros)
Definition: scip_sol.c:2379
#define BMScheckEmptyMemory()
Definition: memory.h:157
#define FALSE
Definition: def.h:96
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
static SCIP_RETCODE runSCIP(int argc, char **argv)
Definition: cmain.c:112
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:292
int main(int argc, char **argv)
Definition: cmain.c:111
static SCIP_RETCODE interactive(SCIP *scip)
Definition: cmain.c:99
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:208
SCIP_Bool SCIPfileExists(const char *filename)
Definition: misc.c:10967
static SCIP_RETCODE readParams(SCIP *scip, const char *filename)
Definition: cmain.c:38
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2622
SCIP_RETCODE SCIPreadProb(SCIP *scip, const char *filename, const char *extension)
Definition: scip_prob.c:339
#define NULL
Definition: lpi_spx1.cpp:164
#define SCIP_CALL(x)
Definition: def.h:393
SCIP_RETCODE SCIPincludeSepaGMI(SCIP *scip)
Definition: sepa_gmi.c:824
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
void SCIPprintVersion(SCIP *scip, FILE *file)
Definition: scip_general.c:155
Gomory Mixed-Integer Cuts.
SCIP_RETCODE SCIPstartInteraction(SCIP *scip)
Definition: scip_dialog.c:242
SCIP_RETCODE SCIPreadParams(SCIP *scip, const char *filename)
Definition: scip_param.c:751
void SCIPprintError(SCIP_RETCODE retcode)
Definition: scip_general.c:220
static SCIP_RETCODE fromCommandLine(SCIP *scip, const char *filename)
Definition: cmain.c:64
default SCIP plugins
SCIP callable library.
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:324
void SCIPenableDebugSol(SCIP *scip)
Definition: scip_debug.c:57