Scippy

GCG

Branch-and-Price & Column Generation for Everyone

graph_tclique.cpp
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 graph_tclique.cpp
29  * @brief interface to the SCIP tclique graph library
30  * @author Annika Thome
31  * @author Martin Bergner
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 /*lint -e39*/
36 #include <cassert>
37 #include "graph_tclique.h"
38 
39 #define TCLIQUE_CALL_EXC(x) do \
40  { \
41  SCIP_Bool _restat_; \
42  if( (_restat_ = (x)) != TRUE ) \
43  { \
44  SCIPerrorMessage("Error <%d> in function call\n", _restat_); \
45  throw std::exception(); \
46  } \
47  } \
48  while( FALSE )
49 
50 #define TCLIQUE_CALL(x) do \
51  { \
52  SCIP_Bool _restat_; \
53  if( (_restat_ = (x)) != TRUE ) \
54  { \
55  SCIPerrorMessage("Error <%d> in function call\n", _restat_); \
56  return SCIP_ERROR; \
57  } \
58  } \
59  while( FALSE )
60 
61 
62 namespace gcg {
63 
65 {
66  TCLIQUE_CALL_EXC( tcliqueCreate(&graph) );
67 }
68 
69 SCIP_RETCODE GraphTclique::addNNodes(int _n_nodes)
70 {
71  return SCIP_INVALIDCALL;
72 }
73 
74 SCIP_RETCODE GraphTclique::addNNodes(int _n_nodes, std::vector<int> weights)
75 {
76  return SCIP_INVALIDCALL;
77 }
78 
79 
81 {
82  tcliqueFree(&graph);
83 }
84 
86 {
87  return tcliqueGetNNodes(graph);
88 }
89 
91 {
92  return tcliqueGetNEdges(graph);
93 }
94 
95 SCIP_RETCODE GraphTclique::getEdges(std::vector<void*>& edges)
96 {
97  return SCIP_INVALIDCALL;
98 }
99 
100 
101 SCIP_Bool GraphTclique::isEdge(int i, int j)
102 {
103  assert(i >= 0);
104  assert(j >= 0);
105 
106  return tcliqueIsEdge(graph, i, j);
107 }
108 
110 {
111  assert( i >= 0);
112  return int( tcliqueGetLastAdjedge(graph,i)-tcliqueGetFirstAdjedge(graph, i)+1 );
113 }
114 
115 std::vector<int> GraphTclique::getNeighbors(int i)
116 {
117  assert(i >= 0);
118  std::vector<int> part(tcliqueGetFirstAdjedge(graph, i), tcliqueGetLastAdjedge(graph,i)+1);
119  return part;
120 }
121 
122 SCIP_RETCODE GraphTclique::addNode(int i, int weight)
123 {
124  assert(i >= getNNodes());
125  TCLIQUE_CALL( tcliqueAddNode(graph,i,weight) );
126  return SCIP_OKAY;
127 }
128 
129 SCIP_RETCODE GraphTclique::addNode()
130 {
131  return SCIP_INVALIDCALL;
132 }
133 
134 SCIP_RETCODE GraphTclique::deleteNode(int i)
135 { /*lint -e715*/
136  return SCIP_ERROR;
137 }
138 
139 SCIP_RETCODE GraphTclique::addEdge(int i, int j)
140 {
141  assert(i >=0);
142  assert(i < getNNodes());
143  assert(j >=0);
144  assert(j < getNNodes());
145 
146  TCLIQUE_CALL( tcliqueAddEdge(graph,i,j) );
147  return SCIP_OKAY;
148 
149 }
150 
151 SCIP_RETCODE GraphTclique::addEdge(int i, int j, double weight)
152 {
153  return SCIP_INVALIDCALL;
154 }
155 
156 SCIP_RETCODE GraphTclique::setEdge(int i, int j, double weight)
157 {
158  return SCIP_INVALIDCALL;
159 }
160 
161 double GraphTclique::getEdgeWeight(int i, int j)
162 {
163  return 0.0;
164 }
165 
166 std::vector<std::pair<int, double> > GraphTclique::getNeighborWeights(int i)
167 {
168  return std::vector<std::pair<int, double> >();
169 }
170 
171 SCIP_RETCODE GraphTclique::deleteEdge(int i, int j)
172 { /*lint -e715*/
173  return SCIP_ERROR;
174 }
175 
176 
177 SCIP_RETCODE GraphTclique::flush()
178 {
179  TCLIQUE_CALL( tcliqueFlush(graph) );
180 
181  return SCIP_OKAY;
182 }
183 
185 {
186  assert( i >= 0);
187  assert( i <= getNNodes());
188  const TCLIQUE_WEIGHT* weights;
189  weights = tcliqueGetWeights(graph);
190  return weights[i];
191 }
192 
193 SCIP_RETCODE GraphTclique::normalize(){
194  // this function is used only in GraphGCG
195  return SCIP_INVALIDCALL;
196 }
197 
199 {
200  return 0.0;
201 }
202 
203 
204 } /* namespace gcg */
virtual SCIP_RETCODE addNNodes(int _n_nodes)
#define TCLIQUE_CALL_EXC(x)
virtual ~GraphTclique()
virtual double getEdgeWeight(int i, int j)
virtual std::vector< int > getNeighbors(int i)
virtual SCIP_RETCODE getEdges(std::vector< void * > &edges)
virtual int getNNeighbors(int i)
virtual SCIP_RETCODE addEdge(int i, int j)
#define TCLIQUE_CALL(x)
virtual int graphGetWeights(int i)
virtual double getEdgeWeightPercentile(double q)
virtual SCIP_RETCODE deleteEdge(int i, int j)
interface to the SCIP tclique graph library
virtual SCIP_RETCODE deleteNode(int i)
virtual SCIP_RETCODE setEdge(int i, int j, double weight)
virtual SCIP_RETCODE flush()
virtual int getNNodes()
virtual SCIP_Bool isEdge(int i, int j)
virtual SCIP_RETCODE normalize()
virtual int getNEdges()
virtual std::vector< std::pair< int, double > > getNeighborWeights(int i)
virtual SCIP_RETCODE addNode()