Scippy

GCG

Branch-and-Price & Column Generation for Everyone

matrixgraph.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program */
4 /* GCG --- Generic Column Generation */
5 /* a Dantzig-Wolfe decomposition based extension */
6 /* of the branch-cut-and-price framework */
7 /* SCIP --- Solving Constraint Integer Programs */
8 /* */
9 /* Copyright (C) 2010-2021 Operations Research, RWTH Aachen University */
10 /* Zuse Institute Berlin (ZIB) */
11 /* */
12 /* This program is free software; you can redistribute it and/or */
13 /* modify it under the terms of the GNU Lesser General Public License */
14 /* as published by the Free Software Foundation; either version 3 */
15 /* of the License, or (at your option) any later version. */
16 /* */
17 /* This program is distributed in the hope that it will be useful, */
18 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
19 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
20 /* GNU Lesser General Public License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with this program; if not, write to the Free Software */
24 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
25 /* */
26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27 
28 /**@file matrixgraph.h
29  * @brief miscellaneous matrixgraph methods for structure detection
30  * @author Martin Bergner
31  * @author Annika Thome
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 
37 #ifndef GCG_MATRIXGRAPH_H_
38 #define GCG_MATRIXGRAPH_H_
39 #include "objscip/objscip.h"
40 #include "tclique/tclique.h"
41 #include "weights.h"
42 #include "pub_decomp.h"
43 #include "bridge.h"
44 #include "graph_interface.h"
45 #include "class_partialdecomp.h"
46 #include "class_detprobdata.h"
47 #include <exception>
48 #include <vector>
49 #include <string>
50 
51 namespace gcg {
52 
53 template <class T>
54 class MatrixGraph {
55 public:
56  std::string name;
57 protected:
58  SCIP* scip_;
59  int nconss;
60  int nvars;
65 
66 public:
67  /** Constructor */
69  SCIP* scip, /**< SCIP data structure */
70  Weights w /**< weights for the given graph */
71  );
72 
73  /** Destructor */
74  virtual ~MatrixGraph();
75 
76  /** writes the graph to the given file.
77  * The format is graph dependent
78  */
79  virtual SCIP_RETCODE writeToFile(
80  int fd, /**< file descriptor where the graph should be written to */
81  SCIP_Bool writeweights /**< whether to write weights */
82  )
83  {
84  SCIP_CALL(graphiface->writeToFile(fd, writeweights) );
85  return SCIP_OKAY;
86  }
87 
88 
89  virtual SCIP_RETCODE createDecompFromPartition(
90  DEC_DECOMP** decomp /**< decomposition structure to generate */
91  )
92  {
93  return SCIP_ERROR;
94  }
95 
96 
97 
98  /** amplifies a partialdec by dint of a graph created with open constraints and open variables of the partialdec */
99  virtual SCIP_RETCODE createPartialdecFromPartition(
100  PARTIALDECOMP* oldpartialdec, /**< partialdec which should be amplifies */
101  PARTIALDECOMP** firstpartialdec, /**< pointer to buffer the new partialdec amplified by dint of the graph */
102  PARTIALDECOMP** secondpartialdec, /**< pinter to buffer the new partialdec whose border is amplified by dint of the graph */
103  DETPROBDATA* detprobdata /**< detection process information and data */
104  )
105  {
106  return SCIP_ERROR;
107  }
108 
109  /**
110  * reads the partition from the given file.
111  * The format is graph dependent. The default is a file with one line for each node a
112  */
113  virtual SCIP_RETCODE readPartition(
114  const char* filename /**< filename where the partition is stored */
115  )
116  {
117  SCIP_CALL( graphiface->readPartition(filename) );
118  return SCIP_OKAY;
119  }
120 
121  /** set the number of dummy nodes */
122  void setDummynodes(int dummynodes_)
123  {
124  dummynodes = dummynodes_;
125  }
126 
127  int getDummynodes() const
128  {
129  return dummynodes;
130  }
131 
132  /** return a partition of the nodes */
133  virtual std::vector<int> getPartition()
134  {
135  return graphiface->getPartition();
136  }
137 
138  virtual SCIP_RETCODE createFromMatrix(
139  SCIP_CONS** conss, /**< constraints for which graph should be created */
140  SCIP_VAR** vars, /**< variables for which graph should be created */
141  int nconss_, /**< number of constraints */
142  int nvars_ /**< number of variables */
143  ) { return SCIP_ERROR; }
144 
145  /** creates a graph with open constraints and open variables of the partialdec */
146  virtual SCIP_RETCODE createFromPartialMatrix(
147  DETPROBDATA* detprobdata,
148  PARTIALDECOMP* partialdec
149  ) { return SCIP_ERROR; }
150 
151 
152  virtual int getNNonzeroes() const
153  {
154  return nnonzeroes;
155  }
156 };
157 
158 }
159 
160 #endif
miscellaneous graph interface methods
virtual std::vector< int > getPartition()
Definition: matrixgraph.h:133
weight class for graphs
virtual SCIP_RETCODE writeToFile(int fd, SCIP_Bool writeweights)
Definition: matrixgraph.h:79
virtual SCIP_RETCODE createFromMatrix(SCIP_CONS **conss, SCIP_VAR **vars, int nconss_, int nvars_)
Definition: matrixgraph.h:138
virtual SCIP_RETCODE createFromPartialMatrix(DETPROBDATA *detprobdata, PARTIALDECOMP *partialdec)
Definition: matrixgraph.h:146
GraphInterface * graphiface
Definition: matrixgraph.h:63
void setDummynodes(int dummynodes_)
Definition: matrixgraph.h:122
virtual SCIP_RETCODE writeToFile(int fd, SCIP_Bool writeweights)=0
virtual std::vector< int > getPartition() const
int getDummynodes() const
Definition: matrixgraph.h:127
virtual int getNNonzeroes() const
Definition: matrixgraph.h:152
std::string name
Definition: matrixgraph.h:56
virtual ~MatrixGraph()
bridge
class to manage partial decompositions
virtual SCIP_RETCODE readPartition(const char *filename)
Definition: matrixgraph.h:113
class storing (potentially incomplete) decompositions
virtual SCIP_RETCODE createDecompFromPartition(DEC_DECOMP **decomp)
Definition: matrixgraph.h:89
virtual SCIP_RETCODE readPartition(const char *filename)=0
MatrixGraph(SCIP *scip, Weights w)
class storing partialdecs and the problem matrix
virtual SCIP_RETCODE createPartialdecFromPartition(PARTIALDECOMP *oldpartialdec, PARTIALDECOMP **firstpartialdec, PARTIALDECOMP **secondpartialdec, DETPROBDATA *detprobdata)
Definition: matrixgraph.h:99
public methods for working with decomposition structures