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