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 #include <iostream>
36 #include <fstream>
37 #include <string>
38 #include "GomoryHuTree.h"
39 #include "objscip/objscip.h"
40 #include "scip/def.h"
41 
42 #ifdef SCIP_WITH_ZLIB
43 #include "gzstream.h"
44 typedef gzstream::igzstream tspifstream;
45 #else
46 typedef std::ifstream tspifstream;
47 #endif
48 
49 
50 namespace tsp
51 {
52 
53 /** SCIP file reader for TSP data files */
54 class ReaderTSP : public scip::ObjReader
55 {
56 public:
57 
59 
60  /** default constructor */
62  : scip::ObjReader(scip, "tspreader", "file reader for TSP files", "tsp")
63  {
64  /* add TSP reader parameters */
65  (void) SCIPaddBoolParam(scip,
66  "reading/tspreader/round_lengths", "should lenghts of edges be rounded to nearest integer?",
67  &round_lengths_, FALSE, TRUE, NULL, NULL);
68  }
69 
70  /** destructor */
71  virtual ~ReaderTSP()
72  {
73  }
74 
75  /** destructor of file reader to free user data (called when SCIP is exiting) */
76  virtual SCIP_DECL_READERFREE(scip_free);
77 
78  /** problem reading method of reader
79  *
80  * possible return values for *result:
81  * - SCIP_SUCCESS : the reader read the file correctly and created an appropritate problem
82  * - SCIP_DIDNOTRUN : the reader is not responsible for given input file
83  *
84  * If the reader detected an error in the input file, it should return with RETCODE SCIP_READERR or SCIP_NOFILE.
85  */
86  virtual SCIP_DECL_READERREAD(scip_read);
87 
88  /** problem writing method of reader; NOTE: if the parameter "genericnames" is TRUE, then
89  * SCIP already set all variable and constraint names to generic names; therefore, this
90  * method should always use SCIPvarGetName() and SCIPconsGetName();
91  *
92  * possible return values for *result:
93  * - SCIP_SUCCESS : the reader read the file correctly and created an appropritate problem
94  * - SCIP_DIDNOTRUN : the reader is not responsible for given input file
95  *
96  * If the reader detected an error in the writing to the file stream, it should return
97  * with RETCODE SCIP_WRITEERROR.
98  */
99  virtual SCIP_DECL_READERWRITE(scip_write);
100 
101 private:
102 
103  /** parses the node list */
104  void getNodesFromFile(
105  tspifstream& filedata, /**< filestream containing the data to extract */
106  double* x_coords, /**< double array to be filled with the x-coordinates of the nodes */
107  double* y_coords, /**< same for y-coordinates */
108  GRAPH* graph /**< the graph which is to be generated by the nodes */
109  );
110 
111  /** method asserting, that the file has had the correct format and everything was set correctly */
112  bool checkValid(
113  GRAPH* graph, /**< the constructed graph, schould not be NULL */
114  const std::string& name, /**< the name of the file */
115  const std::string& type, /**< the type of the problem, should be "TSP" */
116  const std::string& edgeweighttype, /**< type of the edgeweights, should be "EUC_2D", "MAX_2D", "MAN_2D",
117  * "ATT", or "GEO" */
118  int nnodes /**< dimension of the problem, should at least be one */
119  );
120 
121  /** adds a variable to both halfedges and captures it for usage in the graph */
122  SCIP_RETCODE addVarToEdges(
123  SCIP* scip, /**< SCIP data structure */
124  GRAPHEDGE* edge, /**< an edge of the graph */
125  SCIP_VAR* var /**< variable corresponding to that edge */
126  );
127 
128 };/*lint !e1712*/
129 
130 } /* namespace tsp */
131 
132 #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
ReaderTSP(SCIP *scip)
Definition: ReaderTSP.h:61
virtual SCIP_DECL_READERWRITE(scip_write)
C++ wrapper classes for SCIP.
std::ifstream tspifstream
Definition: ReaderTSP.h:46
#define SCIP_Bool
Definition: def.h:91
SCIP_Bool round_lengths_
Definition: ReaderTSP.h:58
virtual SCIP_DECL_READERREAD(scip_read)
C++ wrapper for file readers and writers.
Definition: objreader.h:52
virtual ~ReaderTSP()
Definition: ReaderTSP.h:71
#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