Scippy

SCIP

Solving Constraint Integer Programs

ReaderTSP.h
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 (c) 2002-2024 Zuse Institute Berlin (ZIB) */
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 ReaderTSP.h
26  * @brief C++ file reader for TSP data files
27  * @author Timo Berthold
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #ifndef __TSPREADER_H__
33 #define __TSPREADER_H__
34 
35 
36 #include <string>
37 #include "objscip/objscip.h"
38 #include "scip/def.h"
39 #include "GomoryHuTree.h" // for GRAPH
40 #include "scip/pub_fileio.h"
41 
42 
43 namespace tsp
44 {
45 
46 /** SCIP file reader for TSP data files */
47 class ReaderTSP : public scip::ObjReader
48 {
49 public:
50 
52 
53  /** default constructor */
55  : scip::ObjReader(scip, "tspreader", "file reader for TSP files", "tsp")
56  {
57  /* add TSP reader parameters */
58  (void) SCIPaddBoolParam(scip,
59  "reading/tspreader/round_lengths", "should lenghts of edges be rounded to nearest integer?",
60  &round_lengths_, FALSE, TRUE, NULL, NULL);
61  }
62 
63  /** destructor */
64  virtual ~ReaderTSP()
65  {
66  }
67 
68  /** destructor of file reader to free user data (called when SCIP is exiting) */
69  virtual SCIP_DECL_READERFREE(scip_free);
70 
71  /** problem reading method of reader
72  *
73  * possible return values for *result:
74  * - SCIP_SUCCESS : the reader read the file correctly and created an appropritate problem
75  * - SCIP_DIDNOTRUN : the reader is not responsible for given input file
76  *
77  * If the reader detected an error in the input file, it should return with RETCODE SCIP_READERR or SCIP_NOFILE.
78  */
79  virtual SCIP_DECL_READERREAD(scip_read);
80 
81  /** problem writing method of reader; NOTE: if the parameter "genericnames" is TRUE, then
82  * SCIP already set all variable and constraint names to generic names; therefore, this
83  * method should always use SCIPvarGetName() and SCIPconsGetName();
84  *
85  * possible return values for *result:
86  * - SCIP_SUCCESS : the reader read the file correctly and created an appropritate problem
87  * - SCIP_DIDNOTRUN : the reader is not responsible for given input file
88  *
89  * If the reader detected an error in the writing to the file stream, it should return
90  * with RETCODE SCIP_WRITEERROR.
91  */
92  virtual SCIP_DECL_READERWRITE(scip_write);
93 
94 private:
95 
96  /** parses the node list */
97  SCIP_RETCODE getNodesFromFile(
98  SCIP_FILE* file, /**< file containing the data to extract */
99  double* x_coords, /**< double array to be filled with the x-coordinates of the nodes */
100  double* y_coords, /**< same for y-coordinates */
101  GRAPH* graph /**< the graph which is to be generated by the nodes */
102  );
103 
104  /** method asserting, that the file has had the correct format and everything was set correctly */
105  bool checkValid(
106  GRAPH* graph, /**< the constructed graph, schould not be NULL */
107  const std::string& name, /**< the name of the file */
108  const std::string& type, /**< the type of the problem, should be "TSP" */
109  const std::string& edgeweighttype, /**< type of the edgeweights, should be "EUC_2D", "MAX_2D", "MAN_2D",
110  * "ATT", or "GEO" */
111  int nnodes /**< dimension of the problem, should at least be one */
112  );
113 
114  /** adds a variable to both halfedges and captures it for usage in the graph */
115  SCIP_RETCODE addVarToEdges(
116  SCIP* scip, /**< SCIP data structure */
117  GRAPHEDGE* edge, /**< an edge of the graph */
118  SCIP_VAR* var /**< variable corresponding to that edge */
119  );
120 
121 };/*lint !e1712*/
122 
123 } /* namespace tsp */
124 
125 #endif
#define NULL
Definition: def.h:267
virtual SCIP_DECL_READERFREE(scip_free)
#define FALSE
Definition: def.h:94
#define TRUE
Definition: def.h:93
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
generator for global cuts in undirected graphs
ObjReader(SCIP *scip, const char *name, const char *desc, const char *extension)
Definition: objreader.h:70
struct SCIP_File SCIP_FILE
Definition: pub_fileio.h:43
ReaderTSP(SCIP *scip)
Definition: ReaderTSP.h:54
virtual SCIP_DECL_READERWRITE(scip_write)
C++ wrapper classes for SCIP.
wrapper functions to map file i/o to standard or zlib file i/o
#define SCIP_Bool
Definition: def.h:91
SCIP_Bool round_lengths_
Definition: ReaderTSP.h:51
virtual SCIP_DECL_READERREAD(scip_read)
C++ wrapper for file readers and writers.
Definition: objreader.h:52
virtual ~ReaderTSP()
Definition: ReaderTSP.h:64
#define nnodes
Definition: gastrans.c:74
common defines and data types used in all packages of SCIP
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:57