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