Scippy

SCIP

Solving Constraint Integer Programs

cppmain.cpp
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 examples/TSP/src/cppmain.cpp
26  * @brief main file for C++ TSP example using SCIP as a callable library
27  * @author Tobias Achterberg
28  * @author Timo Berthold
29  *
30  * This is an example of using SCIP to solve the TSP problem on undirected graphs. See the doxygen documentation for an
31  * explanation.
32  */
33 
34 /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include <iostream>
37 
38 /* include SCIP components */
39 #include "objscip/objscip.h"
41 
42 /* include TSP specific components */
43 #include "ReaderTSP.h"
44 #include "ConshdlrSubtour.h"
45 #include "HeurFarthestInsert.h"
46 #include "Heur2opt.h"
47 #include "HeurFrats.h"
48 #include "EventhdlrNewSol.h"
49 
50 using namespace scip;
51 using namespace tsp;
52 using namespace std;
53 
54 /** creates and runs a SCIP instance with default and TSP plugins */
55 static
57  int argc, /**< number of arguments from the shell */
58  char** argv /**< array of shell arguments */
59  )
60 {
61  SCIP* scip = NULL;
62 
63 
64  /*********
65  * Setup *
66  *********/
67 
68  /* initialize SCIP */
69  SCIP_CALL( SCIPcreate(&scip) );
70 
71  /* we explicitly enable the use of a debug solution for this main SCIP instance */
72  SCIPenableDebugSol(scip);
73 
74  /* include TSP specific plugins */
75  SCIP_CALL( SCIPincludeObjReader(scip, new ReaderTSP(scip), TRUE) );
79  SCIP_CALL( SCIPincludeObjHeur(scip, new Heur2opt(scip), TRUE) );
80  SCIP_CALL( SCIPincludeObjHeur(scip, new HeurFrats(scip), TRUE) );
81 
82  /* include default SCIP plugins */
84 
85 
86  /**********************************
87  * Process command line arguments *
88  **********************************/
89 
90  SCIP_CALL( SCIPprocessShellArguments(scip, argc, argv, "sciptsp.set") );
91 
92 
93  /********************
94  * Deinitialization *
95  ********************/
96 
97  SCIP_CALL( SCIPfree(&scip) );
98 
100 
101  return SCIP_OKAY;
102 }
103 
104 /** main method starting TSP code */
105 int main(
106  int argc, /**< number of arguments from the shell */
107  char** argv /**< array of shell arguments */
108  )
109 {
110  SCIP_RETCODE retcode;
111 
112  retcode = runSCIP(argc, argv);
113  if( retcode != SCIP_OKAY )
114  {
115  SCIPprintError(retcode);
116  return -1;
117  }
118 
119  return 0;
120 }
#define BMScheckEmptyMemory()
Definition: memory.h:157
SCIP_RETCODE SCIPincludeObjEventhdlr(SCIP *scip, scip::ObjEventhdlr *objeventhdlr, SCIP_Bool deleteobject)
2-Optimum - combinatorial improvement heuristic for TSP
#define TRUE
Definition: def.h:95
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:292
farthest insert - combinatorial heuristic for TSP
SCIP_RETCODE SCIPincludeObjHeur(SCIP *scip, scip::ObjHeur *objheur, SCIP_Bool deleteobject)
Definition: objheur.cpp:204
C++ wrapper for default SCIP plugins.
SCIP_RETCODE SCIPincludeObjConshdlr(SCIP *scip, scip::ObjConshdlr *objconshdlr, SCIP_Bool deleteobject)
Definition: pqueue.h:37
#define NULL
Definition: lpi_spx1.cpp:164
C++ wrapper classes for SCIP.
#define SCIP_CALL(x)
Definition: def.h:393
event handler for new solutions in TSP
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
C++ constraint handler for TSP subtour elimination constraints.
SCIP_RETCODE SCIPincludeObjReader(SCIP *scip, scip::ObjReader *objreader, SCIP_Bool deleteobject)
Definition: objreader.cpp:155
SCIP_RETCODE SCIPprocessShellArguments(SCIP *scip, int argc, char **argv, const char *defaultsetname)
Definition: scipshell.c:243
fractional travelling salesman heuristic - Rounding heuristic for TSP
C++ file reader for TSP data files.
int main(int argc, char **argv)
Definition: cppmain.cpp:38
void SCIPprintError(SCIP_RETCODE retcode)
Definition: scip_general.c:220
static SCIP_RETCODE runSCIP(int argc, char **argv)
Definition: cppmain.cpp:56
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:324
void SCIPenableDebugSol(SCIP *scip)
Definition: scip_debug.c:57