Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

MinSteinerTreeDirectedCut.h
Go to the documentation of this file.
1 
42 #pragma once
43 
44 #include <ogdf/external/abacus.h>
45 
46 #include <ogdf/basic/Graph.h>
49 #include <ogdf/basic/Logger.h>
50 
51 #include <memory>
53 
55 // heuristics, approximation algorithms:
57 
58 
59 // turn on/off logging for STP b&c algorithm
60 //#define OGDF_STP_EXACT_LOGGING
61 
62 // TODO: Add module option for max flow algorithm
63 
64 namespace ogdf {
65 
67 
70 template<typename T>
72 protected:
73  // all the settings
74  const char *m_configFile;
75  double m_eps;
76 #ifdef OGDF_STP_EXACT_LOGGING
77  Logger::Level m_outputLevel;
78 #endif
79  std::unique_ptr< MaxFlowModule<double> > m_maxFlowModuleOption;
94 
95  // Abacus LP classes
96  class Sub;
97  class EdgeConstraint;
98  class DegreeConstraint;
100  class DirectedCutConstraint;
101  class EdgeVariable;
102 
103 public:
104  class Master;
105 
106  // a lot of setter methods
108  void setEpsilon(double eps) {
109  m_eps = eps;
110  }
112  void setConfigFile(const char *configfile) {
113  m_configFile = configfile;
114  }
115 #ifdef OGDF_STP_EXACT_LOGGING
116  void setOutputLevel(Logger::Level outputLevel)
118  {
119  m_outputLevel = outputLevel;
120  }
121 #endif
124  {
125  m_maxFlowModuleOption.reset(module);
126  }
128  void useDegreeConstraints(bool b)
129  {
130  m_addDegreeConstraints = b;
131  }
134  {
135  m_addIndegreeEdgeConstraints = b;
136  }
138  void useGSEC2Constraints(bool b)
139  {
140  m_addGSEC2Constraints = b;
141  }
144  {
145  m_addFlowBalanceConstraints = b;
146  }
149  {
150  m_maxNrAddedCuttingPlanes = b;
151  }
153  void useTerminalShuffle(bool b)
154  {
155  m_shuffleTerminals = b;
156  }
158  void useBackCuts(bool b)
159  {
160  m_backCutComputation = b;
161  }
163  void useNestedCuts(bool b)
164  {
165  m_nestedCutComputation = b;
166  }
169  {
170  m_separationStrategy = b;
171  }
174  {
175  m_saturationStrategy = b;
176  }
179  {
180  m_minCardinalityCuts = b;
181  }
184  m_primalHeuristic = b;
185  }
188  {
189  OGDF_ASSERT(b >= 0);
190  OGDF_ASSERT(b <= 2);
191  m_callPrimalHeuristic = b;
192  }
195  {
196  m_poolSizeInitFactor = b;
197  }
198 
200  : m_configFile(nullptr)
201  , m_eps(1e-6)
202 #ifdef OGDF_STP_EXACT_LOGGING
203  , m_outputLevel(Logger::Level::Default)
204 #endif
205  , m_maxFlowModuleOption(new MaxFlowGoldbergTarjan<double>())
206  , m_addDegreeConstraints(true)
207  , m_addIndegreeEdgeConstraints(true)
208  , m_addGSEC2Constraints(true)
209  , m_addFlowBalanceConstraints(true)
210  , m_maxNrAddedCuttingPlanes(500)
211  , m_shuffleTerminals(true)
212  , m_backCutComputation(true)
213  , m_nestedCutComputation(true)
214  , m_separationStrategy(1)
215  , m_saturationStrategy(1)
216  , m_minCardinalityCuts(true)
217  , m_callPrimalHeuristic(1)
218  , m_primalHeuristic(nullptr)
219  , m_poolSizeInitFactor(5)
220  {
221  }
222 
223 protected:
224  virtual T computeSteinerTree(const EdgeWeightedGraph<T> &G, const List<node> &terminals, const NodeArray<bool> &isTerminal,
225  EdgeWeightedGraphCopy<T> *&finalSteinerTree) override;
226 };
227 
229 template<typename T>
231 {
232 public:
242  Master(const EdgeWeightedGraph<T> &wG,
243  const List<node> &terminals,
244  const NodeArray<bool> &isTerminal,
245  double eps,
246  bool relaxed = false);
247 
249  virtual ~Master()
250  {
251  delete[] m_bestSolution;
252  delete[] m_terminals;
253  delete[] m_nodes;
254  delete[] m_edges;
255  delete m_pGraph;
256  delete m_pWeightedGraphPH;
257  delete m_pCutPool;
258  }
259 
261  void setConfigFile(const char *filename)
262  {
263  m_configfile = filename;
264  }
265 #ifdef OGDF_STP_EXACT_LOGGING
266  void setOutputLevel(Level outputLevel)
268  {
269  this->globalLogLevel(Level::Default);
270  this->localLogMode(LogMode::Log);
271  if (outputLevel >= Level::Minor
272  && outputLevel <= Level::Force) {
273  this->localLogLevel((Level)outputLevel);
274  this->globalMinimumLogLevel((Level)outputLevel);
275  }
276  }
277 #endif
280  m_maxFlowModule = module;
281  }
282 
285  {
286  return m_maxFlowModule;
287  }
288 
290  void useDegreeConstraints(bool b)
291  {
293  }
296  {
298  }
300  void useGSEC2Constraints(bool b)
301  {
303  }
306  {
308  }
311  {
313  this->maxConAdd(m_maxNrAddedCuttingPlanes);
314  this->maxConBuffered(m_maxNrAddedCuttingPlanes);
315  }
317  void useTerminalShuffle(bool b)
318  {
319  m_shuffleTerminals = b;
320  }
322  void useBackCuts(bool b)
323  {
325  }
327  void useNestedCuts(bool b)
328  {
330  }
333  {
334  OGDF_ASSERT(b >= 1);
335  OGDF_ASSERT(b <= 2);
337  }
340  {
341  OGDF_ASSERT(b >= 1);
342  OGDF_ASSERT(b <= 2);
344  }
347  {
349  }
352  {
353  OGDF_ASSERT(b >= 0);
354  OGDF_ASSERT(b <= 2);
356  }
359  {
361  }
362 
364  void setPrimalHeuristic(MinSteinerTreeModule<double> *pMinSteinerTreeModule) {
365  m_primalHeuristic.reset(pMinSteinerTreeModule);
366  }
368  std::unique_ptr< MinSteinerTreeModule<double> > &getPrimalHeuristic() {return m_primalHeuristic;}
369 
372 
374  virtual abacus::Sub *firstSub() override
375  {
376  return new Sub(this);
377  }
378 
380  bool isSolutionEdge(edge e) const
381  {
382  return ((m_isSolutionEdge[m_mapToBidirectedGraph1[e]])
383  || (m_isSolutionEdge[m_mapToBidirectedGraph2[e]]));
384  }
385 
387  const Graph &graph() const {return *m_pGraph;}
388 
390  int nNodes() const {return m_pGraph->numberOfNodes();}
392  int nEdges() const {return m_pGraph->numberOfEdges();}
394  int nEdgesU() const {return m_nEdgesU;}
396  node rootNode() const {return m_root;}
397 
399  int nTerminals() const {return m_nTerminals;}
401  const node *terminals() const {return m_terminals;}
403  const List<node> &terminalsList() const {return m_terminalsList;}
405  node terminal(int i) const {return m_terminals[i];}
407  bool isTerminal(node n) const {return m_isTerminal[n];}
409  const NodeArray<bool> isTerminal() const {return m_isTerminal;}
410 
412  int edgeID(edge e) const {return m_edgeIDs[e];}
414  int nodeID(node n) const {return m_nodeIDs[n];}
415 
417  node *nodes() const {return m_nodes;}
419  const NodeArray<int> &nodeIDs() const {return m_nodeIDs;}
421  const EdgeArray<int> &edgeIDs() const {return m_edgeIDs;}
422 
424  edge getEdge(int i) const {return m_edges[i];}
426  node getNode(int i) const {return m_nodes[i];}
427 
429  const EdgeArray<double> &capacities() const {return m_capacities;}
431  double capacities(edge e) const {return m_capacities[e];}
432 
434  edge twin(edge e) const {return m_twin[e];}
435  // the twin edge array
436  const EdgeArray<edge> &twins() const {return m_twin;}
437 
439  EdgeVariable *getVar(edge e) const {return m_edgeToVar[e];}
441  EdgeVariable *getVarTwin(edge e) const {return m_edgeToVar[m_twin[e]];}
442 
444  bool relaxed() const {return m_relaxed;}
445 
447  double solutionValue() const {return this->primalBound();}
449  double *bestSolution() const {return m_bestSolution;}
451  void updateBestSolution(double *values);
453  void updateBestSolutionByEdges(const List<edge> &sol);
454 
456  void setRelaxedSolValue(double val) {m_relaxedSolValue = val;}
458  void setNIterRoot(int val) {m_nIterRoot = val;}
459 
465  bool computeBackCuts() const {return m_backCutComputation;}
469  bool callPrimalHeuristic() const {return m_callPrimalHeuristic > 0;}
476 
478  bool shuffleTerminals() const {return m_shuffleTerminals;}
479 
481  int maxPoolSize() const {return m_maxPoolSize;}
484  {
485  if (m_poolSizeMax < m_pCutPool->size())
486  m_poolSizeMax = m_pCutPool->size();
487  }
489  int poolSizeInit() const {return m_poolSizeInit;}
490 
492  void incNrCutsTotal(int val) {m_nrCutsTotal += val;}
494  void incNrCutsTotal() {m_nrCutsTotal++;}
496  int nrCutsTotal() const {return m_nrCutsTotal;}
497 
498  /*
499  * Methods for primal heuristics.
500  * Naming convention: suffix "PH"
501  */
502  /*
503  * Edge weighted bidirected graph; used and modified for primal heuristics.
504  * Required for calling MinSteinerTreeModule algorihms
505  */
506  EdgeWeightedGraph<double> &weightedGraphPH() {return *m_pWeightedGraphPH;}
508  const List<node> &terminalListPH() const {return m_terminalListPH;}
510  const NodeArray<bool> &isTerminalPH() const {return m_isTerminalPH;}
512  node rootNodePH() const {return m_rootPH;}
514  edge edgeGToWgPH(edge e) const {return m_edgesGToWgPH[e];}
516  edge edgeWgToGPH(edge e) const {return m_edgesWgToGPH[e];}
517 
518  /*
519  * some additional timers
520  */
522  StopwatchWallClock *separationTimer() {return &m_separationTimer;}
524  StopwatchWallClock *timerMinSTCut() {return &m_timerMinSTCut;}
526  StopwatchWallClock *primalHeuristicTimer() {return &m_primalHeuristicTimer;}
527 
528 protected:
530  virtual void initializeOptimization() override;
532  virtual void terminateOptimization() override;
534  virtual void initializeParameters() override;
535 
536 private:
538 
540  const char *m_configfile;
541 
543  std::unique_ptr< MinSteinerTreeModule<double> > m_primalHeuristic;
544 
546  bool m_relaxed;
547 
550 
553 
556 
559 
568 
573 
580 
593 
596 
598  double *m_bestSolution;
600 
601  /*
602  * Stuff for primal heuristics
603  */
618 
631 
640 
650  /*
651  * basic strategy:
652  * Computes mincut between the root and a terminal. Saturates cutedges afterwards.
653  * Continues with same terminal until no violated cut is found. Considers next terminal.
654  * 1: When switching to next terminal saturated edges remain saturated (default)
655  * 2: When switching to next terminal saturated edges are reset to original capacity
656  */
659  /*
660  * for all cutedges e:
661  * 1: capacity[e]=1 (default)
662  * 2: capacity[e]=1/C with C=nr of cutedges
663  */
665 
667  /*
668  * adds epsilon to each arc capacity before computing the minimum cut
669  */
671 
673  /*
674  * 0: no PH
675  * 1: call PH right before branchting
676  * 2: call PH every iteration
677  */
679 
686 
687  Master(const Master &rhs);
688  const Master &operator= (const Master &rhs);
689 };
690 
692 template<typename T>
694 {
695 public:
697  explicit Sub(abacus::Master *master);
699  Sub(abacus::Master *master, abacus::Sub *father, abacus::BranchRule *branchRule);
701  virtual ~Sub()
702  {
703  }
704 
705 #ifdef OGDF_STP_EXACT_LOGGING
706  void printCurrentSolution(bool onlyNonZeros = true);
708 #endif
709 
710 protected:
712  virtual bool feasible() override;
713 
715  virtual int separate() override
716  {
717  if (m_alreadySeparated == -1) {
718  m_alreadySeparated = mySeparate();
719  }
720  return m_alreadySeparated;
721  }
723  int mySeparate();
724 
726  void myImprove();
727 
728 #ifdef OGDF_STP_EXACT_LOGGING
729  void printMainInfosInFeasible(bool header = false) const;
731 #endif
732 
733 private:
734 #ifdef OGDF_STP_EXACT_LOGGING
735  void printConstraint(abacus::Constraint *constraint, Logger::Level level = Logger::Level::Default) const;
737 #endif
738 
741 
744 
759 
761  /*
762  * 0: no PH
763  * 1: call PH right before branchting
764  * 2: call PH every iteration
765  */
767 
769  virtual Sub *generateSon(abacus::BranchRule *rule) override
770  {
771  return new Sub(master_, this, rule);
772  }
773 };
774 
776 template<typename T>
778 {
779 public:
781 #if 0
782  const abacus::Sub *sub,
783 #endif
784  int id,
785  edge e,
786  double coeff,
787  double lb = 0.0,
788  double ub = 1.0,
790  )
791  : abacus::Variable(master, nullptr /*, sub*/, false, false, coeff, lb, ub, vartype)
792  , m_edge(e)
793  , m_id(id)
794  {
795  }
796 
798  edge theEdge() const {return m_edge;}
800  int id() const {return m_id;}
802  double coefficient() const {return this->obj();}
804  node source() const {return m_edge->source();}
806  node target() const {return m_edge->target();}
807 
808 private:
812  int m_id;
813 };
814 
815 
817 template<typename T>
819 {
820 public:
822  edge e1,
823  edge e2,
824  int factor = 1.0,
826  double rhs = 1.0)
827  : abacus::Constraint(master, nullptr, sense, rhs, false, false, false)
828  , m_e1(e1)
829  , m_e2(e2)
830  , m_factor(factor)
831  {
832  }
833 
835  double coeff(const abacus::Variable *v) const override
836  {
837  EdgeVariable *edgeVar = (EdgeVariable*)v;
838  edge e = edgeVar->theEdge();
839  if ((e != m_e1) && (e != m_e2))
840  return 0.0;
841  return m_factor;
842  }
843 
844 private:
850  int m_factor;
851 };
852 
853 
855 template<typename T>
857 {
858 public:
860  node n,
861  double coeffIn,
862  double coeffOut,
863  abacus::CSense::SENSE sense,
864  double rhs)
865  : abacus::Constraint(master, nullptr, sense, rhs, false, false, false)
866  , m_node(n)
867  , m_coeffIn(coeffIn)
868  , m_coeffOut(coeffOut)
869  {
870  }
871 
873  virtual double coeff(const abacus::Variable *v) const override
874  {
875  EdgeVariable *edgeVar = (EdgeVariable*)v;
876  edge e = edgeVar->theEdge();
877  if (e->target() == m_node) {
878  return m_coeffIn;
879  } else {
880  if (e->source() == m_node) {
881  return m_coeffOut;
882  } else {
883  return 0.0;
884  }
885  }
886  }
887 
889  node theNode() const {return m_node;}
890 
891 private:
895  double m_coeffIn;
897  double m_coeffOut;
898 };
899 
900 
902 template<typename T>
904 {
905 public:
907  edge e,
908  double coeffIn,
909  double coeffEdge,
910  abacus::CSense::SENSE sense,
911  double rhs)
912  : abacus::Constraint(master, nullptr, sense, rhs, false, false, false)
913  , m_edge(e)
914  , m_coeffIn(coeffIn)
915  , m_coeffEdge(coeffEdge)
916  {
917  }
918 
920  double coeff(const abacus::Variable *v) const override
921  {
922  EdgeVariable *edgeVar = (EdgeVariable*)v;
923  edge e = edgeVar->theEdge();
924  // the edge
925  if ((e->source() == m_edge->source()) && (e->target() == m_edge->target()))
926  return m_coeffEdge;
927  // all edges to vertices x != source
928  if (e->target() != m_edge->source())
929  return 0.0;
930  // reverse edge
931  if (e->source() == m_edge->target())
932  return 0.0;
933  // all ingoing edges of the source (except the reverse edge, of course)
934  return m_coeffIn;
935  }
936 
938  edge theEdge() const {return m_edge;}
939 private:
943  double m_coeffIn;
945  double m_coeffEdge;
946 };
947 
948 
950 template<typename T>
952 {
953 public:
955  : abacus::Constraint(master, nullptr, abacus::CSense::Greater, 1.0, false, false, false)
956  , m_pGraph(&g)
957  , m_name("")
958  {
959 #ifdef OGDF_STP_EXACT_LOGGING
960  cout << "Creating new DirectedCutConstraint: " << std::endl;
961 #endif
962  m_hashKey = 0;
963  m_marked.init(g);
964  for (node n : g.nodes) {
966  m_marked[n] = minSTCut->isInFrontCut(n);
967 #ifdef OGDF_STP_EXACT_LOGGING
968  if(m_marked[n]) {
969  // TODO: Use lout instead
970  cout << " marked node " << n << std::endl;
971  }
972 #endif
973  } else {
975  m_marked[n] = !minSTCut->isInBackCut(n);
976  }
977  if (m_marked[n]) {
978  m_nMarkedNodes++;
979  m_hashKey += n->index();
980  }
981  }
982  m_hashKey += m_nMarkedNodes*g.numberOfNodes()*g.numberOfNodes();
983 #ifdef OGDF_STP_EXACT_LOGGING
984  cout << " front cut edges:" << std::endl;
985  for (edge e : g.edges) {
986  if(minSTCut->isFrontCutEdge(e)) {
987  cout << " " << e << std::endl;
988  }
989  }
990  cout << " back cut edges:" << std::endl;
991  for (edge e : g.edges) {
992  if(minSTCut->isBackCutEdge(e)) {
993  cout << " " << e << std::endl;
994  }
995  }
996 #endif
997  }
998 
999  double coeff(const abacus::Variable *v) const override;
1000 
1002  bool active(node n) const {
1003  return m_marked[n];
1004  }
1006  bool cutedge(edge e) const {
1007  return ((m_marked[e->source()]) && (!m_marked[e->target()]));
1008  }
1010  int nMarkedNodes() const { return m_nMarkedNodes; }
1012  bool marked(node n) const { return m_marked[n]; }
1014  unsigned hashKey() const override { return m_hashKey; };
1016  bool equal(const ConVar *cv) const override;
1018  const char *name() const override { return m_name; }
1019 
1020 private:
1022  const Graph *m_pGraph;
1023 
1025  /*
1026  * A vertex is marked iff it is separated by the cut
1027  * i.e., it is contained in the same set as the target
1028  */
1030 
1033 
1035  unsigned int m_hashKey;
1037  const char *m_name;
1038 };
1039 
1040 
1041 template<typename T>
1043  const EdgeWeightedGraph<T> &wG,
1044  const List<node> &terminals,
1045  const NodeArray<bool> &isTerminal,
1046  double eps,
1047  bool relaxed)
1048  : abacus::Master("MinSteinerTreeDirectedCut::Master", true, false, abacus::OptSense::Min, eps)
1049  , m_maxFlowModule(nullptr)
1050  , m_configfile(nullptr)
1051  , m_relaxed(relaxed)
1052  , m_relaxedSolValue(-1)
1053  , m_nIterRoot(-1)
1054  , m_wG(wG)
1055  , m_pCutPool(nullptr)
1057  , m_poolSizeMax(0)
1058  , m_maxPoolSize(-1)
1059  , m_nrCutsTotal(0)
1060  , m_addGSEC2Constraints(true)
1061  , m_addDegreeConstraints(true)
1065  , m_shuffleTerminals(true)
1066  , m_backCutComputation(true)
1067  , m_nestedCutComputation(true)
1070  , m_minCardinalityCuts(true)
1072 {
1073 #ifdef OGDF_STP_EXACT_LOGGING
1075  << "Master::Master(): default LP solver: "
1076  << this->OSISOLVER_[this->defaultLpSolver()] << endl;
1077 #endif
1078  m_pGraph = new Graph();
1079 
1080  edge e1, e2;
1081  int i = 0;
1082 
1083  m_nodes = new node[m_wG.numberOfNodes()];
1086  m_nTerminals = terminals.size();
1087  m_root = nullptr;
1088 
1089 #ifdef OGDF_STP_EXACT_LOGGING
1090  lout(Level::Default) << "Master::Master(): nTerminals="
1091  << m_nTerminals << flush;
1092  lout(Level::Minor) << " terminals: " << flush;
1093 #endif
1094  NodeArray<node> nodeMapping(m_wG);
1095 
1096  for (node nOrig : m_wG.nodes) {
1097  node n = m_pGraph->newNode();
1098  nodeMapping[nOrig] = n;
1099  m_nodes[i] = n;
1100  m_nodeIDs[n] = i;
1101  m_isTerminal[n] = isTerminal[nOrig];
1102  if (m_isTerminal[n]) {
1103 #ifdef OGDF_STP_EXACT_LOGGING
1104  lout(Level::Minor) << n << "," << flush;
1105 #endif
1106  m_terminalsList.pushBack(n);
1107  }
1108  i++;
1109  }
1110 #ifdef OGDF_STP_EXACT_LOGGING
1111  lout(Level::Minor) << endl << "Master::Master(): edges: ";
1112 #endif
1113  m_terminals = new node[m_nTerminals];
1114  i = 0;
1115  for (ListIterator<node> tIt = m_terminalsList.begin(); tIt.valid(); tIt++) {
1116  m_terminals[i++] = *tIt;
1117  }
1118 
1119  m_nEdgesU = m_wG.numberOfEdges();
1121  m_twin.init(*m_pGraph);
1123  m_edges = new edge[2*m_nEdgesU];
1124 
1125  m_mapToOrigGraph.init(*m_pGraph);
1128 
1129  i = 0;
1130  for (edge eOrig : m_wG.edges) {
1131  e1 = m_pGraph->newEdge(nodeMapping[eOrig->source()],
1132  nodeMapping[eOrig->target()]);
1133  e2 = m_pGraph->newEdge(nodeMapping[eOrig->target()], nodeMapping[eOrig->source()]);
1134  m_capacities[e1] = m_capacities[e2] = m_wG.weight(eOrig);
1135  m_twin[e1] = e2;
1136  m_twin[e2] = e1;
1137  m_edges[i] = e1;
1138  m_edgeIDs[e1] = i++;
1139  m_edges[i] = e2;
1140  m_edgeIDs[e2] = i++;
1141  m_mapToOrigGraph[e1] = eOrig;
1142  m_mapToOrigGraph[e2] = eOrig;
1143  m_mapToBidirectedGraph1[eOrig] = e1;
1144  m_mapToBidirectedGraph2[eOrig] = e2;
1145 #ifdef OGDF_STP_EXACT_LOGGING
1146  lout(Level::Minor) << " " << eOrig << "[" << e1 << ", " << e2 << "]" << flush;
1147 #endif
1148  }
1149 #ifdef OGDF_STP_EXACT_LOGGING
1150  lout(Level::Default) << endl;
1151 #endif
1152  for (node n : m_pGraph->nodes) {
1153  if (m_isTerminal[n]) {
1154  // possibility to set the root node
1155  // default: terminal with highest degree
1156  if (!m_root)
1157  m_root = n;
1158  else {
1159  if (m_root->degree() < n->degree())
1160  m_root = n;
1161  }
1162  }
1163  }
1164 
1165 #ifdef OGDF_STP_EXACT_LOGGING
1166  lout(Level::Medium) << "Master::Master(): m_root=" << m_root << endl;
1167 #endif
1168 
1169  m_isSolutionEdge.init(*m_pGraph, false);
1170  m_bestSolution = new double[m_pGraph->numberOfEdges()];
1171  for (i = 0; i < m_pGraph->numberOfEdges(); i++) {
1172  m_bestSolution[i] = 1.0;
1173  }
1174 
1175  // stuff for "primal heuristic"
1177  m_nodesGToWgPH.init(*m_pGraph);
1178  m_edgesGToWgPH.init(*m_pGraph);
1181 
1182  for (node nOrig : m_pGraph->nodes) {
1184  m_nodesGToWgPH[nOrig] = n;
1185  m_isTerminalPH[n] = m_isTerminal[nOrig];
1186  if (m_isTerminalPH[n])
1187  m_terminalListPH.pushBack(n);
1188  if (m_root == nOrig)
1189  m_rootPH = n;
1190  }
1191 
1192  for (edge eOrig : m_pGraph->edges) {
1193  edge e = m_pWeightedGraphPH->newEdge(m_nodesGToWgPH[eOrig->source()], m_nodesGToWgPH[eOrig->target()], 0.0);
1194  m_edgesGToWgPH[eOrig] = e;
1195  m_edgesWgToGPH[e] = eOrig;
1196  }
1197 
1198  // set default primal heuristic module to takahashi algorithm
1200 }
1201 
1202 template<typename T>
1203 void
1205 {
1206  if (m_configfile) {
1207  bool objectiveInteger = false;
1208  try {
1210  }
1211  catch (AlgorithmFailureException) {
1212 #ifdef OGDF_STP_EXACT_LOGGING
1214  << "Master::initializeParameters(): Error reading parameters."
1215  << "Using default values." << endl;
1216 #endif
1217  }
1218 #ifdef OGDF_STP_EXACT_LOGGING
1219  int outputLevel;
1220  getParameter("OutputLevel", outputLevel);
1221  setOutputLevel(static_cast<Level>(outputLevel));
1222 #endif
1223  int solver = (OSISOLVER) findParameter("DefaultLpSolver", 12, OSISOLVER_);
1224  this->defaultLpSolver((OSISOLVER)solver);
1225  getParameter("AddGSEC2Constraints", m_addGSEC2Constraints);
1226  getParameter("AddDegreeConstraints", m_addDegreeConstraints);
1227  getParameter("AddIndegreeEdgeConstraints", m_addIndegreeEdgeConstraints);
1228  getParameter("AddFlowBalanceConstraints", m_addFlowBalanceConstraints);
1229  getParameter("MaxNrCuttingPlanes", m_maxNrAddedCuttingPlanes);
1230  getParameter("ShuffleTerminals", m_shuffleTerminals);
1231  getParameter("BackCutComputation", m_backCutComputation);
1232  getParameter("NestedCutComputation", m_nestedCutComputation);
1233  getParameter("SeparationStrategy", m_separationStrategy);
1234  getParameter("SaturationStrategy", m_saturationStrategy);
1235  getParameter("MinCardinalityCuts", m_minCardinalityCuts);
1236  getParameter("PrimalHeuristic", m_callPrimalHeuristic);
1237  getParameter("PoolSizeInitFactor", m_poolSizeInitFactor);
1238  getParameter("ObjInteger", objectiveInteger);
1239  this->objInteger(objectiveInteger);
1240  }
1241 
1242 #ifdef OGDF_STP_EXACT_LOGGING
1243  lout(Level::High)
1244  << "Master::initializeParameters(): parameters:"<< endl
1245  << "\tLP-Solver " << OSISOLVER_[this->defaultLpSolver()] << endl
1246  << "\tOutputLevel " << this->localLogLevel() << endl
1247  << "\tAddDegreeConstraints " << m_addDegreeConstraints << endl
1248  << "\tAddIndegreeEdgeConstraints " << m_addIndegreeEdgeConstraints << endl
1249  << "\tAddGSEC2Constraints " << m_addGSEC2Constraints << endl
1250  << "\tAddFlowBalanceConstraints " << m_addFlowBalanceConstraints << endl
1251  << "\tMaxNrCuttingPlanes " << m_maxNrAddedCuttingPlanes << endl
1252  << "\tShuffleTerminals " << m_shuffleTerminals << endl
1253  << "\tBackCutComputation " << m_backCutComputation << endl
1254  << "\tMinCardinalityCuts " << m_minCardinalityCuts << endl
1255  << "\tNestedCutComputation " << m_nestedCutComputation << endl;
1256  if (m_nestedCutComputation) {
1257  lout(Level::High)
1258  << "\t SeparationStrategy " << m_separationStrategy << endl
1259  << "\t SaturationStrategy " << m_saturationStrategy << endl;
1260  }
1261  lout(Level::High)
1262  << "\tPrimalHeuristic " << m_callPrimalHeuristic << endl
1263  << "\tPoolSizeInitFactor " << m_poolSizeInitFactor << endl
1264  << "\tObjective integer " << this->objInteger() << endl
1265  << endl;
1266 #endif
1268 }
1269 
1270 template<typename T>
1271 void
1273 {
1274 #ifdef OGDF_STP_EXACT_LOGGING
1275  lout(Level::High)
1276  << "Master::initializeOptimization(): Instance properties:" << endl
1277  << "\t(nNodes,nEdges) : (" << m_pGraph->numberOfNodes()
1278  << ", " << m_nEdgesU << ")" << endl
1279  << "\tNumber of terminals : " << m_nTerminals << endl
1280  << "\tRoot node : " << m_root << endl
1281  << endl;
1282 #endif
1283  int i;
1284 
1285  // buffer for variables; one for each directed edge
1287 
1288  // add (edge) variables
1289  EdgeVariable *eVar;
1290  m_edgeToVar.init(*m_pGraph, nullptr);
1291 
1293  if (m_relaxed) {
1294  vartype = abacus::VarType::Continuous;
1295  }
1296 
1297  for (i = 0; i < m_pGraph->numberOfEdges(); i++) {
1298  edge e = m_edges[i];
1299  if (e->target() != m_root // not going into root
1300  && !e->isSelfLoop()) {
1301  eVar = new EdgeVariable(this, i, e, m_capacities[e], 0.0, 1.0, vartype);
1302 #ifdef OGDF_STP_EXACT_LOGGING
1303  lout(Level::Minor) << "\tadding variable x_" << i << ", edge " << e << endl;
1304 #endif
1305  }
1306  else {
1307  // ub = lb = 0 is not nice, but makes life easier -> ids
1308  OGDF_ASSERT(m_capacities[e] >= 0);
1309  eVar = new EdgeVariable(this, i, e, m_capacities[e], 0.0, 0.0, vartype);
1310 #ifdef OGDF_STP_EXACT_LOGGING
1311  lout(Level::Minor) << "\tmuting variable x_" << i << ", edge " << e << endl;
1312 #endif
1313  }
1314  variables.push(eVar);
1315  m_edgeToVar[e] = eVar;
1316  }
1317 
1318  // add constraints
1319  int nCons = 0;
1321  nCons += m_nEdgesU;
1323  nCons += m_pGraph->numberOfNodes();
1325  nCons += m_pGraph->numberOfEdges();
1327  nCons += m_pGraph->numberOfNodes()-1;
1328 
1329  ArrayBuffer<abacus::Constraint*> basicConstraints(nCons);
1330 
1331  i = 0;
1332  if (m_addGSEC2Constraints) {
1333  EdgeArray<bool> marked(*m_pGraph, false);
1334  for (edge e : m_pGraph->edges) {
1335  if (!marked[e]
1336  && !e->isSelfLoop()) { // we have to ignore self-loops here
1337  EdgeConstraint *newCon =
1338  new EdgeConstraint(this, e, m_twin[e], 1, abacus::CSense::Less, 1.0);
1339  basicConstraints.push(newCon);
1340  marked[e] = true;
1341  marked[m_twin[e]] = true;
1342 
1343 #ifdef OGDF_STP_EXACT_LOGGING
1344  lout(Level::Minor) << "\tadding constraint " << i++ << " GSEC2: edge " << e << endl;
1345 #endif
1346  }
1347  }
1348  }
1349 
1350  // "degree" constraints:
1351  // (1) forall terminals t != m_root: x(delta-(t)) == 1
1352  // (2) forall non-temrinals n : x(delta-(n)) <= 1
1353  // (3) for the root : x(delta+(m_root)) >= 1
1355  {
1356  for (node n : m_pGraph->nodes) {
1357  DegreeConstraint *newCon;
1358  if (n == m_root) {
1359  // (3)
1360  newCon = new DegreeConstraint(this, n, 0.0, 1.0, abacus::CSense::Greater, 1.0);
1361  }
1362  else {
1363  if (m_isTerminal[n]) {
1364  // (1)
1365  newCon = new DegreeConstraint(this, n, 1.0, 0.0, abacus::CSense::Equal, 1.0);
1366  }
1367  else {
1368  // (2)
1369  newCon = new DegreeConstraint(this, n, 1.0, 0.0, abacus::CSense::Less, 1.0);
1370  }
1371  }
1372  basicConstraints.push(newCon);
1373 
1374 #ifdef OGDF_STP_EXACT_LOGGING
1375  lout(Level::Minor) << "\tadding constraint " << i++ << " Degree: node " << n << endl;
1376 #endif
1377  }
1378  }
1379 
1381  for (edge e : m_pGraph->edges) {
1382  if (e->source() != m_root) {
1383  DegreeEdgeConstraint *newCon =
1384  new DegreeEdgeConstraint(this, e, 1.0, -1.0, abacus::CSense::Greater, 0.0);
1385  basicConstraints.push(newCon);
1386 
1387 #ifdef OGDF_STP_EXACT_LOGGING
1388  lout(Level::Minor) << "\tadding constraint " << i++ << " Indegree: edge " << e << endl;
1389 #endif
1390  }
1391  }
1392  }
1393 
1395  for (node n : m_pGraph->nodes) {
1396  if (!m_isTerminal[n]) {
1397  DegreeConstraint *newCon =
1398  new DegreeConstraint(this, n, -1.0, 1.0, abacus::CSense::Greater, 0.0);
1399  basicConstraints.push(newCon);
1400 
1401 #ifdef OGDF_STP_EXACT_LOGGING
1402  lout(Level::Minor) << "\tadding constraint " << i++ << " Flow-Balance: node " << n << endl;
1403 #endif
1404  }
1405  }
1406  }
1407 
1410  // initialize the non-duplicate cut pool
1412 
1413  this->initializePools(
1414  basicConstraints,
1415  variables,
1416  0,
1417  nCons,
1418  true);
1419 
1420 #ifdef OGDF_STP_EXACT_LOGGING
1421  lout(Level::Minor) << "Master::initializeOptimization() done." << endl;
1422 #endif
1423 }
1424 
1425 
1426 template<typename T>
1427 void
1429 {
1430  int nOnesInSol = 0;
1431  for (int i = 0; i < m_pGraph->numberOfEdges(); i++) {
1432  if (m_bestSolution[i] > 0.5) {
1433  m_isSolutionEdge[m_edges[i]] = true;
1434  nOnesInSol++;
1435  }
1436  }
1437 
1438 #ifdef OGDF_STP_EXACT_LOGGING
1439  lout(Level::High) << endl;
1440  if (is_lout(Level::Medium)) {
1441  lout(Level::Medium) << "\toptimum solution edges:" << endl;
1442  for (edge e : m_pGraph->edges) {
1443  if (m_isSolutionEdge[e])
1444  lout(Level::Medium) << "\t" << e << endl;
1445  }
1446  }
1447  lout(Level::Medium) << endl;
1448 
1449  lout(Level::High)
1450  << "Finished optimization. Statistics:" << endl
1451  << "Solution " << endl
1452  << " value " << this->primalBound() << endl
1453  << " rounded sol. value " << ((int)this->primalBound()) << endl
1454  << " nr edges " << nOnesInSol << endl
1455  << "Status " << this->STATUS_[this->status()] << endl
1456  << "Primal/dual bound " << this->primalBound() << "/" << this->dualBound() << endl
1457  << "Relaxed solution value " << this->m_relaxedSolValue << endl
1458  << "Nr subproblems " << this->nSub() << endl
1459  << "Nr solved LPs " << this->nLp() << endl
1460  << "nr solved LPs in root " << m_nIterRoot << endl
1461  << endl
1462 
1463  << "LP Solver " << this->OSISOLVER_[this->defaultLpSolver()] << endl
1464  << "Enumeration strategy " << this->ENUMSTRAT_[this->enumerationStrategy()] << endl
1465  << "Branching strategy " << this->BRANCHINGSTRAT_[this->branchingStrategy()] << endl
1466  << "Objective integer " << (this->objInteger()? "true":"false") << endl
1467  << endl
1468 
1469  << "Total time (centi sec) " << this->totalTime()->centiSeconds() << endl
1470  << "Total time " << *this->totalTime() << endl
1471  << "Total cow-time " << *this->totalCowTime() << endl
1472  << "LP time " << *this->lpTime() << endl
1473  << "LP solver time " << *this->lpSolverTime() << endl
1474  << "Separation time " << this->m_separationTimer << endl
1475  << "Minimum Cut time " << this->m_timerMinSTCut << endl
1476  << "Primal heuristic time " << this->m_primalHeuristicTimer << endl
1477  << endl
1478 
1479  << "Initial cutpool size " << this->m_poolSizeInit << endl
1480  << "Maximum cutpool size " << this->m_poolSizeMax << endl
1481  << "Nr separated cuts " << m_nrCutsTotal << endl;
1482 
1483  int nDuplicates, nCollisions;
1484  m_pCutPool->statistics(nDuplicates, nCollisions);
1485  lout(Level::High)
1486  << "Cutpool duplications " << nDuplicates << endl
1487  << "Cutpool collisions " << nCollisions << endl
1488  << endl;
1489 #endif
1490 }
1491 
1492 
1493 template<typename T>
1494 void
1496 {
1497  double eps = this->eps();
1498  double oneMinusEps = 1.0 - eps;
1499  for (int i = 0; i < m_pGraph->numberOfEdges(); i++) {
1500  if (values[i] > oneMinusEps)
1501  m_bestSolution[i] = 1.0;
1502  else
1503  if (values[i] < eps)
1504  m_bestSolution[i] = 0.0;
1505  else
1506  m_bestSolution[i] = values[i];
1507  }
1508 }
1509 
1510 template<typename T>
1511 void
1513 {
1514  for (int i = 0; i < m_pGraph->numberOfEdges(); i++) {
1515  m_bestSolution[i] = 0.0;
1516  }
1517  for (ListConstIterator<edge> it = sol.begin(); it.valid(); it++) {
1518  m_bestSolution[m_edgeIDs[*it]] = 1.0;
1519  }
1520 }
1521 
1522 
1523 template<typename T>
1525  : abacus::Sub(master,0,0,0)
1526  , m_alreadySeparated(-1)
1527 {
1528  m_pMaster = (Master*) master;
1537 }
1538 
1539 
1540 template<typename T>
1542  : abacus::Sub(master, father, branchRule)
1543  , m_alreadySeparated(-1)
1544 {
1545  m_pMaster = (Master*) master;
1546 #ifdef OGDF_STP_EXACT_LOGGING
1548  << std::setw(7) << this->id()
1549  << std::setw(7) << this->nIter_
1550  << " new subproblem, parent=" << father->id() << endl;
1551 #endif
1560 }
1561 
1562 #ifdef OGDF_STP_EXACT_LOGGING
1563 template<typename T>
1564 void
1566 {
1567  if (header) {
1568  // print header
1570  << endl
1571  << std::setw(7) << "id"
1572  << std::setw(7) << "iter"
1573  << std::setw(10) << "lp value"
1574  << std::setw(10) << "gl. LB"
1575  << std::setw(10) << "gl. UB"
1576  << std::setw(10) << "nSub"
1577  << std::setw(10) << "nOpenSub"
1578  << endl;
1579  }
1580  else {
1582  << std::setw(7) << this->id()
1583  << std::setw(7) << this->nIter_
1584  << std::setw(10) << lp_->value();
1585  if (this->id() == 1)
1586  m_pMaster->lout(Logger::Level::High) << std::setw(10) << "--";
1587  else
1588  m_pMaster->lout(Logger::Level::High) << std::setw(10) << master_->lowerBound();
1589  if (master_->feasibleFound())
1590  m_pMaster->lout(Logger::Level::High) << std::setw(10) << master_->upperBound();
1591  else
1592  m_pMaster->lout(Logger::Level::High) << std::setw(10) << "--";
1594  << std::setw(10) << master_->nSub()
1595  << std::setw(10) << master_->openSub()->number()
1596  << endl;
1598  << "\tcurrent LP:" << endl;
1601  }
1602 }
1603 #endif
1604 
1605 template<typename T>
1606 bool
1608 {
1609  double eps = master_->eps();
1610  double oneMinusEps = 1.0 - eps;
1611 
1612 #ifdef OGDF_STP_EXACT_LOGGING
1613  if (this->nIter_ == 1) {
1614  this->printMainInfosInFeasible(true);
1615  }
1616  else
1617  this->printMainInfosInFeasible(false);
1618 #endif
1619 
1620  // separate directed cuts
1622 
1623  if (m_alreadySeparated > 0) {
1624  if ((m_callPrimalHeuristic == 2) && (!m_pMaster->relaxed())) {
1625  myImprove();
1626  }
1627  return false;
1628  }
1629 
1630  if (this->id() == 1) {
1631  // set some statistics if we are in the root node
1634  }
1635 
1636  if (!m_pMaster->relaxed()) {
1637  // check integrality
1638  for (int i = 0; i < m_pMaster->nEdges(); i++) {
1639  if ((xVal_[i] > eps) && (xVal_[i] < oneMinusEps)) {
1640  // found non-integral solution but no violated directed cuts
1641  // i.e., we have to branch.
1642  // But first, we call the primal heuristic
1643  if (m_callPrimalHeuristic > 0) {
1644  myImprove();
1645  }
1646 
1647 #ifdef OGDF_STP_EXACT_LOGGING
1649  << "\tsolution is fractional -> Branching." << endl;
1650 #endif
1651  return false;
1652  }
1653  }
1654  }
1655 
1656  if (m_pMaster->betterPrimal(lp_->value())) {
1657 #ifdef OGDF_STP_EXACT_LOGGING
1659  << std::setw(7) << this->id()
1660  << std::setw(7) << this->nIter_
1661  << " found better integer solution with value " << lp_->value();
1663  m_pMaster->lout(Logger::Level::Medium) << ", variables > 0:" << endl;
1664  printCurrentSolution();
1665  }
1666  else
1668 #endif
1671  }
1672 
1673  return true;
1674 }
1675 
1676 #ifdef OGDF_STP_EXACT_LOGGING
1677 template<typename T>
1678 void
1680 {
1681  int nOnesInSol = 0;
1682  double eps = master_->eps();
1683  double oneMinusEps = 1.0 - eps;
1684  for (int i = 0; i < nVar(); i++) {
1685  if ((xVal_[i] > -eps) && (xVal_[i] < eps)) {
1686  if (!onlyNonZeros) {
1687  m_pMaster->lout(Logger::Level::Minor) << "\tx" << i << "=0" << flush;
1688  m_pMaster->lout(Logger::Level::Minor) << " [edge " << ((EdgeVariable*)variable(i))->theEdge() << "]"<< endl;
1689  }
1690  }
1691  else
1692  if ((xVal_[i] > oneMinusEps) && (xVal_[i] < 1+eps)) {
1693  m_pMaster->lout(Logger::Level::Minor) << "\tx" << i << "=1" << flush;
1694  m_pMaster->lout(Logger::Level::Minor) << " [edge " << ((EdgeVariable*)variable(i))->theEdge() << "]"<< endl;
1695  nOnesInSol++;
1696  }
1697  else {
1698  m_pMaster->lout(Logger::Level::Minor) << "\tx" << i << "=" << xVal_[i] << flush;
1699  m_pMaster->lout(Logger::Level::Minor) << " [edge " << ((EdgeVariable*)variable(i))->theEdge() << "]"<< endl;
1700  }
1701  }
1702  m_pMaster->lout(Logger::Level::Medium) << "\tnEdges=" << nOnesInSol << endl << flush;
1703 }
1704 #endif
1705 
1706 template<typename T>
1707 int
1709 {
1710 #ifdef OGDF_STP_EXACT_LOGGING
1712  << "Sub::mySeparate(): id="
1713  << this->id() << ", iter=" << this->nIter_ << endl;
1714 #endif
1716  double eps = master_->eps();
1717  double cardEps = eps / 100;
1718  double oneMinusEps = 1 - eps;
1719  node r = m_pMaster->rootNode();
1720  const Graph &g = m_pMaster->graph();
1721  int nEdgesU = m_pMaster->nEdgesU();
1722 
1723  int nTerminals = m_pMaster->nTerminals();
1724  const node *masterTerminals = m_pMaster->terminals();
1725  node *terminal = new node[nTerminals];
1726 
1727  for (int i = 0; i < nTerminals; i++) {
1728  terminal[i] = masterTerminals[i];
1729  }
1730 
1731  if (m_shuffleTerminals) {
1732  // shuffle the ordering of the terminals
1733  int j;
1734  node h = nullptr;
1735  for (int i = 0; i < nTerminals-1; i++) {
1736  j = randomNumber(i, nTerminals-1);
1737  h = terminal[i];
1738  terminal[i] = terminal[j];
1739  terminal[j] = h;
1740  }
1741  }
1742 
1743 #ifdef OGDF_STP_EXACT_LOGGING
1746  << "Sub::mySeparate(): considered terminal ordering: ";
1747  for (int i = 0; i < nTerminals; i++)
1748  m_pMaster->lout(Logger::Level::Medium) << terminal[i] << " ";
1750  }
1751 #endif
1752 
1753  EdgeArray<double> capacities;
1754  capacities.init(g, 0);
1755  for (edge e : g.edges) {
1756  capacities[e] = xVal_[m_pMaster->edgeID(e)];
1758  capacities[e] += cardEps;
1759  }
1760 
1761 #ifdef OGDF_STP_EXACT_LOGGING
1763  << "Sub::mySeparate(): current capacities (>0) for mincut computation:" << endl;
1764  for (edge e : g.edges) {
1765  if (capacities[e] >= 2*cardEps) {
1766  m_pMaster->lout(Logger::Level::Minor) << "\tcapacity[" << e << "]=" << capacities[e] << endl;
1767  }
1768  }
1769 #endif
1770  // Minimum s-t-cut object
1771  MinSTCutMaxFlow<double> minSTCut;
1772  // current terminal
1773  node t;
1774  // index of current terminal
1775  int ti = 0;
1776  // value of current cut
1777  double cutValue = 2.0;
1778  // value of current back cut
1779  double cutValueBack = 0.0;
1780  // for backcut computation
1781  int nOtherNodes = 0;
1782  // upper bound for mincut computation
1783  double uBound = 1 + nEdgesU*cardEps;
1784  // nr of violated cuts found
1785  int cutsFound = 0;
1786 
1787  // buffer for new constraints
1789 
1790  // size of cut and backcut
1791  int cardinalityCut, cardinalityBackcut;
1792  cardinalityCut = cardinalityBackcut = 0;
1793 
1794  // Only relevant if nested cuts are computed:
1795  // this list contains the modified edges i.e., the saturated edges.
1796  // The capacity of these edges can is reset in SeparationStrategy 2
1797  List<edge> modified;
1798 
1799  // main while loop for the computation of the cutting planes
1800  while ((cutsFound < m_maxNrCuttingPlanes) && (ti < nTerminals)) {
1801  t = terminal[ti];
1802  if (t != r) {
1803 #ifdef OGDF_STP_EXACT_LOGGING
1805  << "Sub::mySeparate(): computing minimum cut between root " << r << " and " << t << flush;
1806 #endif
1807  // /compute the minimum r-t-cut
1808  /*
1809  * the cut itself is stored in the integer array with values
1810  * in {0,1,2}. If a node has the value 1, it is contained in the
1811  * subset of the root, 2 indicates the set of the separated node, and
1812  * 0 depicts the set in between
1813  */
1815 
1816  EdgeArray<double> flow;
1818  OGDF_ASSERT(mf != nullptr);
1819  mf->init(g);
1820  mf->useEpsilonTest(cardEps / 100);
1821  cutValue = mf->computeFlow(capacities, r, t, flow);
1822 #ifdef OGDF_STP_EXACT_LOGGING
1823  m_pMaster->lout(Logger::Level::Medium) << " Calculated flow:" << endl;
1824  for (edge flowEdge : g.edges) {
1826  << " " << flowEdge << " : "
1827  << flow[flowEdge] << " / " << capacities[flowEdge] << endl;
1828  }
1829 #endif
1830 
1831  // used epsilon should be smaller than the eps used for cardinality cuts heuristic
1832  minSTCut.setEpsilonTest(new EpsilonTest(cardEps / 100));
1833  minSTCut.call(g, capacities, flow, r, t);
1834 
1836  cutValueBack = 0;
1837 
1838 #ifdef OGDF_STP_EXACT_LOGGING
1839  m_pMaster->lout(Logger::Level::Medium) << ", cutvalue=" << cutValue << flush;
1840 #endif
1841 
1842  // min cardinality
1843  if (m_minCardinalityCuts && (cutValue < uBound)) {
1844  for (edge e : g.edges) {
1845  if (minSTCut.isFrontCutEdge(e)) {
1846  cutValue -= cardEps;
1847  }
1848  if (m_computeBackCuts && minSTCut.isBackCutEdge(e)) {
1849  cutValueBack += capacities[e] - cardEps;
1850  }
1851  }
1852  } else if (m_computeBackCuts) {
1853  for (edge e : g.edges) {
1854  if (minSTCut.isBackCutEdge(e)) {
1855  cutValueBack += capacities[e];
1856  }
1857  }
1858  }
1859 
1860  if (m_saturationStrategy == 2) {
1861  cardinalityCut = cardinalityBackcut = 0;
1862  for (edge e : g.edges) {
1863  if (minSTCut.isFrontCutEdge(e))
1864  cardinalityCut++;
1865  if (m_computeBackCuts && minSTCut.isBackCutEdge(e))
1866  cardinalityBackcut++;
1867  }
1868  }
1869 
1870 #ifdef OGDF_STP_EXACT_LOGGING
1872  << ", actual cutvalue=" << cutValue;
1873  if (m_computeBackCuts)
1875  << ", actual cutValueBack=" << cutValueBack;
1877 #endif
1878  nOtherNodes = 0;
1879 
1880  if (cutValue < oneMinusEps) {
1881  // found violated cut
1882  cutsFound++;
1883  // generate new constraint
1885  // push cut to the set of new constraints
1886  newConstraints.push(newCut);
1887 
1888 #ifdef OGDF_STP_EXACT_LOGGING
1890  << "Sub::mySeparate(): found violated cut:" << endl;
1891  printConstraint(newCut, Logger::Level::Medium);
1892 #endif
1893  if ((m_computeBackCuts)
1894  && !minSTCut.frontCutIsComplementOfBackCut()
1895  && (cutsFound < m_maxNrCuttingPlanes)
1896  && (cutValueBack <= oneMinusEps)) {
1897  cutsFound++;
1898  // generate new constraint
1900  // push cut to the set of new constraints
1901  newConstraints.push(newBackCut);
1902 
1903 #ifdef OGDF_STP_EXACT_LOGGING
1905  << "Sub::mySeparate(): found violated cut (backcut):" << endl;
1906  printConstraint(newBackCut, Logger::Level::Medium);
1907 #endif
1908  } // if (m_computeBackCuts)
1909 
1910  // saturate cut edges in case of nested cut computation
1911  if (m_computeNestedCuts)
1912  {
1913  for (edge e : g.edges) {
1914  if (minSTCut.isFrontCutEdge(e)) {
1915  if (m_saturationStrategy == 2)
1916  capacities[e] = 1.0/(double)cardinalityCut + eps;
1917  else
1918  capacities[e] = 1.0 + eps;
1919  // for resetting the saturation after each iteration
1920  if (m_separationStrategy == 2)
1921  modified.pushBack(e);
1922  }
1923  else {
1924  if ((m_computeBackCuts)
1925  && (nOtherNodes > 0)
1926  && (cutValueBack <= oneMinusEps)
1927  && (minSTCut.isBackCutEdge(e))) {
1928  if (m_saturationStrategy == 2)
1929  capacities[e] = 1.0/(double)cardinalityBackcut + eps;
1930  else
1931  capacities[e] = 1.0 + eps;
1932  // for resetting the saturation after each iteration
1933  if (m_separationStrategy == 2)
1934  modified.pushBack(e);
1935  }
1936  }
1937  }
1938  } // if (m_computeNestedCuts)
1939  } // if (cutValue < oneMinusEps)
1940  } // if (t != r)
1941 
1942  if (!m_computeNestedCuts)
1943  {
1944  ti++;
1945  }
1946  else {
1947  // m_computeNestedCuts == true
1948  if ((cutValue > oneMinusEps) || (r == t)) {
1949  ti++;
1950  if (m_separationStrategy == 2) {
1951  while (!modified.empty()) {
1952  edge e = modified.popFrontRet();
1953  capacities[e] = xVal_[m_pMaster->edgeID(e)];
1955  capacities[e] += cardEps;
1956  }
1957  }
1958  }
1959  }
1960  } // while ((cutsFound < m_maxNrCuttingPlanes) && (ti < nTerminals))
1961 
1962  delete[] terminal;
1963 
1964  m_alreadySeparated = cutsFound;
1965 
1966  if (cutsFound > 0) {
1967  // add separated directed cuts
1968  int nAdded = addCons(newConstraints, m_pMaster->cutPool());
1969  // update statistics
1970  m_pMaster->incNrCutsTotal(nAdded);
1972  if (nAdded != cutsFound) {
1973  // ToDo: is this a problem?!
1974  }
1975  }
1976 
1977 #ifdef OGDF_STP_EXACT_LOGGING
1979  << "Sub::mySeparate(): id="
1980  << this->id() << ", iter=" << this->nIter_
1981  << " separated " << cutsFound << " directed cuts" << endl;
1982 #endif
1984 
1985  return cutsFound;
1986 } // Sub::mySeparate()
1987 
1988 template<typename T>
1989 void
1991 {
1993 
1994 #ifdef OGDF_STP_EXACT_LOGGING
1996  << "Sub::myImprove(): id="
1997  << this->id() << ", iter=" << this->nIter_ << endl;
1998 #endif
1999  double eps = master_->eps();
2000  const Graph &g = m_pMaster->graph();
2002 
2003 #ifdef OGDF_STP_EXACT_LOGGING
2006  << "Sub::myImprove(): current solution:" << endl;
2007  for(edge e : g.edges) {
2009  << "\tx" << m_pMaster->edgeID(e) << "=" << xVal_[m_pMaster->edgeID(e)]
2010  << ", edge " << e << endl;
2011  }
2012  }
2013 #endif
2014 
2015  // set edge weights to eps + (1-x_e)*c_e, forall edges e
2016  // thereby, use minimum of e and twin(e), respectively
2017  double currWeight, twinWeight;
2018  for (edge e : g.edges) {
2019  edge e2 = m_pMaster->twin(e);
2020  currWeight = 1.0-xVal_[m_pMaster->edgeID(e)];
2021  twinWeight = 1.0-xVal_[m_pMaster->edgeID(e2)];
2022  if (twinWeight < currWeight)
2023  currWeight = twinWeight;
2024  if (currWeight < 0)
2025  currWeight = 0;
2026  ewg.setWeight(m_pMaster->edgeGToWgPH(e), eps + currWeight * variable(m_pMaster->edgeID(e))->obj());
2027  }
2028 
2029 #ifdef OGDF_STP_EXACT_LOGGING
2032  << "Sub::myImprove(): edge weights:" << endl;
2033  for (edge e : g.edges) {
2035  << "\tweight[" << e << "]=" << ewg.weight(m_pMaster->edgeGToWgPH(e)) << endl;
2036  }
2037  }
2038 #endif
2039 
2040  // get primal heuristic algorithm
2041  auto &primalHeuristic = m_pMaster->getPrimalHeuristic();
2042 
2043  // the computed heuristic solution
2044  EdgeWeightedGraphCopy<double> *heuristicSolutionWg = nullptr;
2045 
2046 #ifdef OGDF_STP_EXACT_LOGGING
2047  // heuristic solution value for the modified edge weights
2048  double tmpHeuristicSolutionValue =
2049 #endif
2050  // call primal heuristic
2051  primalHeuristic->call(
2055  heuristicSolutionWg);
2056 
2057  // verify that solution is a Steiner tree
2058  bool isSteinerTree = primalHeuristic->isSteinerTree(
2062  *heuristicSolutionWg);
2063 
2064 #ifdef OGDF_STP_EXACT_LOGGING
2066  << "Sub::myImprove(): primal heuristic algorithm returned solution with "
2067  << "value " << tmpHeuristicSolutionValue << ", isSteinerTree=" << isSteinerTree << endl;
2068 #endif
2069 
2070  if (isSteinerTree) {
2071  // actual heuristic solution value, i.e., by using real edge weights
2072  double heuristicSolutionValue = 0.0;
2073  // list of edges in the heuristic solution
2074  List<edge> solutionEdges;
2075 
2076  for (edge e : heuristicSolutionWg->edges) {
2077  edge e2 = m_pMaster->edgeWgToGPH(heuristicSolutionWg->original(e));
2078  solutionEdges.pushBack(e2);
2079  heuristicSolutionValue += m_pMaster->capacities(e2);
2080 #ifdef OGDF_STP_EXACT_LOGGING
2082  << "\t" << e << " -> " << e2 << " c=" << m_pMaster->capacities(e2) << endl;
2083 #endif
2084  }
2085 
2086 #ifdef OGDF_STP_EXACT_LOGGING
2088  << "Sub::myImprove(): found integer solution with value "
2089  << heuristicSolutionValue << endl;
2090 #endif
2091  if (m_pMaster->betterPrimal(heuristicSolutionValue)) {
2092 #ifdef OGDF_STP_EXACT_LOGGING
2094  << std::setw(7) << this->id()
2095  << std::setw(7) << this->nIter_
2096  << " primal heuristic founds better integer solution with value " << heuristicSolutionValue << endl;
2097 #endif
2098  m_pMaster->primalBound(heuristicSolutionValue);
2099  m_pMaster->updateBestSolutionByEdges(solutionEdges);
2100  }
2101  } // if (isSteinerTree)
2102 #ifdef OGDF_STP_EXACT_LOGGING
2103  else {
2105  << "Sub::myImprove(): id="
2106  << this->id() << ", iter=" << this->nIter_
2107  << ": computed solution is no Steiner tree!" << endl;
2108  }
2109 #endif
2110 
2111  delete heuristicSolutionWg;
2113 } // Sub::myImprove
2114 
2115 
2116 #ifdef OGDF_STP_EXACT_LOGGING
2117 template<typename T>
2118 void
2120 {
2121  double eps = master_->eps();
2122  double val = 0;
2124  bool first = true;
2125  for (int i = 0; i < nVar(); i++) {
2126  var = variable(i);
2127  val = constraint->coeff(var);
2128  if ((val > eps) || (val < -eps)) {
2129  if (val > 0) {
2130  if ((val > 1-eps) && (val < 1+eps)) {
2131  if (!first)
2132  m_pMaster->lout(level) << " + ";
2133  }
2134  else {
2135  if (!first)
2136  m_pMaster->lout(level) << " + " << val;
2137  }
2138  }
2139  else {
2140  if ((val < -1+eps) && (val > -1-eps)) {
2141  if (!first)
2142  m_pMaster->lout(level) << " - ";
2143  else
2144  m_pMaster->lout(level) << " -";
2145  }
2146  else {
2147  if (!first)
2148  m_pMaster->lout(level) << " - " << (-1)*val;
2149  else
2150  m_pMaster->lout(level) << val;
2151  }
2152  }
2153  m_pMaster->lout(level) << "x" << i;
2154  first = false;
2155  }
2156  }
2157  m_pMaster->lout(level)
2158  << " " << *(constraint->sense()) << " "
2159  << constraint->rhs() << endl;
2160 } // Sub::printConstraint
2161 #endif
2162 
2163 
2164 
2165 template<typename T>
2166 bool
2168 {
2169  if (m_hashKey != cv->hashKey()) {
2170  return false;
2171  }
2173  if (m_nMarkedNodes != dirCut->nMarkedNodes())
2174  return false;
2175  for (node n : m_pGraph->nodes) {
2176  if (m_marked[n] != dirCut->marked(n)) {
2177  return false;
2178  }
2179  }
2180  return true;
2181 }
2182 
2183 
2184 template<typename T>
2185 double
2187 {
2188  EdgeVariable *edgeVar = (EdgeVariable*)v;
2189  if (this->cutedge(edgeVar->theEdge())) {
2190  return 1.0;
2191  }
2192  return 0.0;
2193 }
2194 
2195 
2196 template<typename T>
2198 {
2199  Master *stpMaster = new Master(G, terminals, isTerminal, m_eps);
2200  if (m_configFile) {
2201  stpMaster->setConfigFile(m_configFile);
2202  }
2203 #ifdef OGDF_STP_EXACT_LOGGING
2204  stpMaster->setOutputLevel(m_outputLevel);
2205 #endif
2212  stpMaster->useBackCuts(m_backCutComputation);
2217  stpMaster->setMaxFlowModule(m_maxFlowModuleOption.get());
2218  if (m_primalHeuristic) {
2220  }
2223  // XXX: should we set stpMaster->objInteger true/false according to weights automatically?
2224 
2225  // now solve LP
2226  stpMaster->optimize();
2227 
2228  // collect solution edges to build Steiner tree
2229  finalSteinerTree = new EdgeWeightedGraphCopy<T>();
2230  finalSteinerTree->createEmpty(G);
2231  T weight(0);
2232  for (edge e = G.firstEdge(); e; e = e->succ()) {
2233  if (stpMaster->isSolutionEdge(e)) {
2234  const node vO = e->source();
2235  node vC = finalSteinerTree->copy(vO);
2236  if (!vC) {
2237  vC = finalSteinerTree->newNode(vO);
2238  }
2239  const node wO = e->target();
2240  node wC = finalSteinerTree->copy(wO);
2241  if (!wC) {
2242  wC = finalSteinerTree->newNode(wO);
2243  }
2244  T edgeCost = G.weight(e);
2245  finalSteinerTree->newEdge(e, edgeCost);
2246  weight += edgeCost;
2247  }
2248  }
2249 
2250  delete stpMaster;
2251  // mincut is already deleted
2252  return weight;
2253 }
2254 
2255 
2256 } // end namespace ogdf
EdgeArray< edge > m_mapToOrigGraph
the undirected edge in the original graph for each arc in m_pGraph
static const char * ENUMSTRAT_[]
Literal values for the enumerators of the corresponding enumeration type.
Definition: master.h:117
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:327
const ogdf::StopwatchCPU * lpSolverTime() const
Return a pointer to the timer measuring the cpu time required by the LP solver.
Definition: master.h:491
CSense * sense()
Returns a pointer to the sense of the constraint.
Definition: constraint.h:115
const ogdf::StopwatchWallClock * totalCowTime() const
Returns a pointer to the timer measuring the total wall clock time.
Definition: master.h:479
double primalBound() const
Returns the value of the primal bound.
Definition: master.h:278
node m_root
the virtual root of our graph. This node is a terminal.
void useIndegreeEdgeConstraints(bool b)
Switch usage of indegree edge constraints (indeg(v) >= outgoing edge(v,x) for all x) on or off...
bool betterPrimal(double x) const
Can be used to check if a value is better than the best know primal bound.
const char * name() const override
return the name of the cut; required method for nonduplpool
void setPoolSizeInitFactor(int b)
Set factor for the initial size of the cutting pool.
void setSeparationStrategy(int b)
Set separation strategy for nested cuts.
void useNestedCuts(bool b)
Switch computation of nested cuts on or off.
const EdgeWeightedGraph< T > & m_wG
the original weighted graph
virtual Sub * generateSon(abacus::BranchRule *rule) override
generates a b&b node
void useNestedCuts(bool b)
Switch computation of nested cuts on or off.
DegreeEdgeConstraint(abacus::Master *master, edge e, double coeffIn, double coeffEdge, abacus::CSense::SENSE sense, double rhs)
EdgeArray< edge > m_edgesWgToGPH
edge mapping m_pWeightedGraphPH -> m_pGraph
bool isTerminal(node n) const
true if n is a terminal
void setEpsilonTest(EpsilonTest *et)
Assigns a new epsilon test.
int nEdges() const
returns the number of edges
void useEpsilonTest(const double &eps)
Change the used EpsilonTest from StandardEpsilonTest to a user given EpsilonTest. ...
void setConfigFile(const char *configfile)
Set a configuration file to use. The contents of the configuration file can override all other used o...
const EdgeArray< int > & edgeIDs() const
lp variable ids of edges
edge m_e2
twin of m_e1, i.e., if m_e1 = (u,v) it holds m_e2 = (v,u)
const NodeArray< bool > isTerminal() const
boolean array of terminal status
bool isBackCutEdge(const edge e) const
Returns whether this edge is entering the back cut.
void updateBestSolutionByEdges(const List< edge > &sol)
updates best found solution by list of edges
The master of the optimization.
Definition: master.h:69
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:336
double eps() const
Returns the zero tolerance.
Definition: global.h:127
This class implements the Directed Cut Integer Linear Program for the Steiner tree problem...
Class for directed cuts (i.e., separated Steiner cuts)
bool frontCutIsComplementOfBackCut() const
Returns whether the front cut is the complement of the backcut.
bool m_addFlowBalanceConstraints
parameter: add flow balance constraints for Steiner nodes n: outdeg(n) >= indeg(n) ...
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Definition: GraphCopy.h:413
node rootNode() const
the designated root node (special terminal)
void init()
Reinitializes the array. Associates the array with no graph.
Definition: EdgeArray.h:320
bool active(node n) const
returns true iff the node n is separated by this cut
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1316
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
int m_factor
factor for edge coefficients in the constraint
void useBackCuts(bool b)
Switch computation of back-cuts on or off.
virtual void initializePools(ArrayBuffer< Constraint *> &constraints, ArrayBuffer< Variable *> &variables, int varPoolSize, int cutPoolSize, bool dynamicCutPool=false)
Sets up the default pools for variables, constraints, and cutting planes.
MinSteinerTreeModule< double > * m_primalHeuristic
int maxPoolSize() const
the maximum pool size during the algorithm
virtual double rhs() const
Returns the right hand side of the constraint.
Definition: constraint.h:130
static const int Graph
Definition: GmlParser.h:59
void incNrCutsTotal(int val)
increases the number of separated directed cuts
EdgeArray< EdgeVariable * > m_edgeToVar
edge -> lp variable
const char * m_name
name of the cut; required method for nonduplpool
friend class Master
Definition: sub.h:70
static bool isSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, const EdgeWeightedGraphCopy< T > &steinerTree)
Checks in O(n) time if a given tree is acually a Steiner Tree.
int nSub() const
returns the number of generated subproblems.
Definition: master.h:506
void init()
Reinitializes the array. Associates the array with no graph.
Definition: NodeArray.h:292
void setMaxFlowModule(MaxFlowModule< double > *module)
Set the maximum flow module to be used for separation.
void setMaxNumberAddedCuttingPlanes(int b)
Set maximum number of added cutting planes per iteration.
BRANCHINGSTRAT branchingStrategy() const
Returns the branching strategy.
Definition: master.h:524
int saturationStrategy() const
strategy for saturating edges during separation; Only relevant for nested cuts
bool m_nestedCutComputation
parameter: compute nested cuts yes/no i.e., saturate all cut edges and recompute the mincut ...
int randomNumber(int low, int high)
Returns random integer between low and high (including).
void useFlowBalanceConstraints(bool b)
Switch usage of flow balance constraints on or off.
bool computeBackCuts() const
parameter: back cut computation
This class serves as an interface for various methods to compute minimum or approximations of minimum...
virtual void init(const Graph &graph, EdgeArray< T > *flow=nullptr)
Initialize the problem with a graph and optional flow array. If no flow array is given, a new ("internal") array will be created. If a flow array is given, the algorithm uses this "external" array.
Definition: MaxFlowModule.h:93
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:208
edge newEdge(node u, node v, T weight)
edge twin(edge e) const
the twin edge, i.e. twin[(u,v)] = (v,u)
void useIndegreeEdgeConstraints(bool b)
Switch usage of indegree edge constraints (indeg(v) >= outgoing edge(v,x) for all x) on or off...
iterator begin()
Returns an iterator to the first element of the list.
Definition: List.h:332
bool m_addIndegreeEdgeConstraints
add constraints concerning the indegree of a node w.r.t. one outgoing edge: indeg(v) >= outgoing edge...
int findParameter(const char *name, unsigned nFeasible, const int *feasible) const
Searches for parameter name in the parameter table.
void useGSEC2Constraints(bool b)
Switch usage of constraints x_uv + x_vu <= 1 on or off.
void setWeight(const edge e, T weight)
DirectedCutConstraint(abacus::Master *master, const Graph &g, const MinSTCutMaxFlow< double > *minSTCut, MinSTCutMaxFlow< double >::cutType _cutType)
Min-st-cut algorithm, that calculates the cut via maxflow.
const NodeArray< bool > & isTerminalPH() const
terminal yes/no (in m_pWeightedGraphPH)
static const char * OSISOLVER_[]
Array for the literal values for possible Osi solvers.
Definition: master.h:212
unsigned int m_hashKey
hashkey of the cut; required method for nonduplpool
void useTerminalShuffle(bool b)
Switch terminal shuffling before separation on or off.
OSISOLVER defaultLpSolver() const
returns the Lp Solver.
Definition: master.h:533
The subproblem.
Definition: sub.h:68
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:95
void setSaturationStrategy(int b)
Set saturation strategy for nested cuts.
int getParameter(const char *name, int &param) const
Searches for parameter name in the parameter table and returns its value in param.
StopwatchWallClock m_timerMinSTCut
timer for minimum st-cut computations. Measures updates + algorithm
bool shuffleTerminals() const
shuffle ordering of terminals before each separation routine
bool isSolutionEdge(edge e) const
returns true iff original edge is contained in optimum solution
bool minCardinalityCuts() const
parameter: compute minimum cardinality cuts
A variable having value 0 or 1.
Definition: vartype.h:50
DegreeConstraint(abacus::Master *master, node n, double coeffIn, double coeffOut, abacus::CSense::SENSE sense, double rhs)
Implementation of the 2(1-1/l)-approximation algorithm for the minimum Steiner tree problem by Matsuy...
double solutionValue() const
solution value after solving the problem, i.e., returns final primal bound
Master problem of Steiner tree branch&cut algorithm.
void useDegreeConstraints(bool b)
Switch usage of degree constraints (like indeg <= 1) on or off.
void stop()
Stops the stopwatch and adds the difference between the current time and the starting time to the tot...
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Definition: Array.h:44
Extends the GraphCopy concept to weighted graphs.
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
Definition: Stopwatch.h:107
int m_nrCutsTotal
total number of separated directed cuts
int m_maxNrAddedCuttingPlanes
parameter: maximum nr of cutting planes per iteration
double uBound(int i) const
Can be used to access the upper of an active variable of the subproblem.
Definition: sub.h:266
Representation of levels in hierarchies.
Definition: Level.h:61
void setSaturationStrategy(int b)
Set saturation strategy for nested cuts.
void useMinCardinalityCuts(bool b)
Switch usage of the cardinality heuristic (minimum-cardinality cuts) on or off.
T computeFlow(EdgeArray< T > &cap, node &s, node &t, EdgeArray< T > &flow)
Only a shortcut for computeValue and computeFlowAfterValue.
cutType
The three types of cuts.
edge edgeWgToGPH(edge e) const
edge mapping m_pWeightedGraphPH -> m_pGraph
bool cutedge(edge e) const
returns true iff the edge is contained in the cut
const node * terminals() const
terminals in an array
const char * m_configfile
problem dependent config file
int m_maxPoolSize
statistic number of cuts in pool
node * m_terminals
terminal index -> terminal node
node rootNodePH() const
root node (in m_pWeightedGraphPH)
void useBackCuts(bool b)
Switch computation of back-cuts on or off.
virtual int separate() override
calls mySeparate() if mySeparate wasn&#39;t called in another procedure
bool objInteger() const
If true then we assume that all feasible solutions have integral objective function values...
Definition: master.h:637
edge m_e1
base edge and twin of m_e2, i.e., if m_e1 = (u,v) it holds m_e2 = (v,u)
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
OpenSub * openSub() const
Returns a pointer to the set of open subproblems.
Definition: master.h:448
EdgeArray< edge > m_mapToBidirectedGraph1
the first directed arc in m_pGraph for an original edge
int number() const
Returns the current number of open subproblems contained in this set.
Definition: opensub.h:68
int nodeID(node n) const
npde -> id of lp variable
void setPrimalHeuristicCallStrategy(int b)
Set primal heuristic call strategy.
T weight(const edge e) const
Level localLogLevel() const
gives the local log-level
Definition: Logger.h:203
bool m_relaxed
parameter: indicates whether we solve the relaxed problem (LP) or the ILP
void setMaxNumberAddedCuttingPlanes(int b)
Set maximum number of added cutting planes per iteration.
int m_alreadySeparated
nr of already separated cuts, default is -1
int nEdgesU() const
returns number of undirected edges, i.e., nEdges()/2
EdgeVariable * getVar(edge e) const
returns the variable assigned to edge e
std::ostream & lout(Level l=Level::Default) const
stream for logging-output (local)
Definition: Logger.h:147
bool m_addGSEC2Constraints
parameter: add GSEC2 constraints yes/no, i.e. x_uv + x_vu <= 1
void setPrimalHeuristicCallStrategy(int b)
Set primal heuristic call strategy.
virtual ~Sub()
The destructor only deletes the sons of the node.
Forms the virtual base class for all possible constraints given in pool format.
Definition: constraint.h:56
void setRelaxedSolValue(double val)
solution value of the root
bool isInFrontCut(const node v) const
Returns whether this node is part of the front cut.
edge newEdge(node v, node w, T weight)
STATUS optimize()
Performs the optimization by branch-and-bound.
void createEmpty(const Graph &wG)
double lowerBound() const
Returns the value of the global lower bound.
Definition: master.h:1524
double * bestSolution() const
the best found solution
int id() const
Returns the identity number of the subproblem.
Definition: sub.h:153
bool m_backCutComputation
parameter: compute back cuts yes/no i.e., outgoing edges of the root-set
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:548
std::unique_ptr< MaxFlowModule< double > > m_maxFlowModuleOption
int m_separationStrategy
parameter: separation strategy, only important if nested cuts are computed
int numberOfEdges() const
Returns the number of edges in the graph.
Definition: Graph_d.h:581
double dualBound() const
Returns the value of the dual bound.
Definition: master.h:293
int level() const
Returns the level of the subproblem in the branch-and-bound tree.
Definition: sub.h:150
bool m_minCardinalityCuts
parameter: compute minimum cardinality cuts
StopwatchWallClock m_separationTimer
timer for separation
NodeArray< bool > m_isTerminalPH
is terminal yes/no (in m_pWeightedGraphPH)
bool relaxed() const
solve relaxed LP or ILP
void setPrimalHeuristic(MinSteinerTreeModule< double > *b)
Set the module option for the primal heuristic (use MinSteinerTreeModule<double> types). Default: MinSteinerTreeModuleTakahashi.
void useTerminalShuffle(bool b)
Switch terminal shuffling before separation on or off.
Constraint for relating the indegree and one outgoing edge of a node.
A continuous variable.
Definition: vartype.h:48
virtual int addCons(ArrayBuffer< Constraint *> &constraints, Pool< Constraint, Variable > *pool=nullptr, ArrayBuffer< bool > *keepInPool=nullptr, ArrayBuffer< double > *rank=nullptr)
Tries to add new constraints to the constraint buffer and a pool.
List< node > m_terminalsList
list of terminals
abacus::NonDuplPool< abacus::Constraint, abacus::Variable > * cutPool()
the non-duplicate cutpool for the separated Steiner cuts
void myImprove()
primal heuristic procedure
EdgeArray< edge > m_edgesGToWgPH
edge mapping m_pGraph -> m_pWeightedGraphPH
bool computeNestedCuts() const
parameter: nested cut computation
void start(bool reset=false)
Starts the stopwatch.
edge firstEdge() const
Returns the first edge in the list of all edges.
Definition: Graph_d.h:603
virtual bool feasible() override
checks if the current solution is feasible, i.e., calls mySeparate()
Contains logging functionality.
std::unique_ptr< MinSteinerTreeModule< double > > m_primalHeuristic
Algorithm used for the primal heuristic.
int m_maxNrCuttingPlanes
maximum nr of cutting planes to be added
void setMaxFlowModule(MaxFlowModule< double > *module)
Set the maximum flow module to be used for separation.
EdgeVariable(abacus::Master *master, int id, edge e, double coeff, double lb=0.0, double ub=1.0, abacus::VarType::TYPE vartype=abacus::VarType::Binary)
bool feasibleFound() const
We use this function, e.g., to adapt the enumeration strategy in the DiveAndBest-Strategy.
double capacities(edge e) const
costs for edge e
EdgeArray< edge > m_mapToBidirectedGraph2
the second directed arc in m_pGraph for an original edge
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
int m_poolSizeInitFactor
parameter: factor for the initial size of the cutting pool
node terminal(int i) const
get terminal with index i
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
virtual double value() const override
Returns the objective function value of the linear program.
Definition: lpsub.h:124
int nrCutsTotal() const
total number of separated directed cuts
NodeArray< node > m_nodesGToWgPH
node mapping m_pGraph -> m_pWeightedGraphPH
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing...
Definition: exceptions.h:308
MaxFlowModule< double > * getMaxFlowModule()
Get the maximum flow module used by separation algorithm.
Includes Abacus.
StopwatchWallClock * timerMinSTCut()
timer for minimum st-cut computations. Measures updates + algorithm
const EdgeArray< double > & capacities() const
edge costs
std::unique_ptr< MinSteinerTreeModule< double > > & getPrimalHeuristic()
the primal heuristic module
virtual void initializeParameters() override
read/set parameters from file
Class for the representation of edges.
Definition: Graph_d.h:291
E popFrontRet()
Removes the first element from the list and returns it.
Definition: List.h:1360
Declaration of class EdgeWeightedGraph.
void useFlowBalanceConstraints(bool b)
Switch usage of flow balance constraints on or off.
int var(Lit p)
Definition: SolverTypes.h:61
void statistics(int &nDuplications, int &nCollisions) const
Returns some statistic information in nDuplicates and nCollisions.
Definition: nonduplpool.h:144
Abstract base class for all branching rules.
Definition: branchrule.h:59
double * xVal_
The last LP-solution.
Definition: sub.h:1512
const List< node > & terminalListPH() const
list of terminals (in m_pWeightedGraphPH)
EdgeConstraint(abacus::Master *master, edge e1, edge e2, int factor=1.0, abacus::CSense::SENSE sense=abacus::CSense::Less, double rhs=1.0)
Class for the representation of nodes.
Definition: Graph_d.h:167
int separationStrategy() const
strategy for separating directed Steiner cuts; Only relevant for nested cuts
Implements a stopwatch measuring wall-clock time.
Definition: Stopwatch.h:195
int callPrimalHeuristicStrategy() const
strategy for calling primal heuristic (PH)
Encapsulates a pointer to a list element.
Definition: List.h:41
const ogdf::StopwatchCPU * totalTime() const
returns a pointer to the timer measuring the total cpu time for the optimization. ...
Definition: master.h:485
void setPoolSizeInitFactor(int b)
Set factor for the initial size of the cutting pool.
const ogdf::StopwatchCPU * lpTime() const
Returns a pointer to the timer measuring the cpu time spent in members of the LP-interface.
Definition: master.h:488
List< node > m_terminalListPH
list of terminal nodes (in m_pWeightedGraphPH)
NodeArray< bool > m_isTerminal
node is terminal yes/no
double m_relaxedSolValue
statistics: solution value of the relaxed master problem
void useMinCardinalityCuts(bool b)
Switch usage of the cardinality heuristic (minimum-cardinality cuts) on or off.
Forms the virtual base class for all possible variables given in pool format.
Definition: variable.h:59
bool callPrimalHeuristic() const
parameter: call primal heuristic yes/no
virtual void initializeOptimization() override
insert variables and base constraints
bool isFrontCutEdge(const edge e) const
Returns whether this edge is leaving the front cut.
bool equal(const ConVar *cv) const override
tests if cuts are equal; required method for nonduplpool
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:287
int nVar() const
Returns the number of active variables.
Definition: sub.h:1838
bool m_addDegreeConstraints
parameter: add constraints concerning the indegree of a node, like: indeg <= 1 for all vertices ...
double coeff(const abacus::Variable *v) const override
Returns the coefficient of the variable v in the constraint.
NodeArray< bool > m_marked
defines if a vertex is on the left side of the cut (false) or not
This class implements the minimum Steiner tree 2-approximation algorithm by Takahashi and Matsuyama w...
void useDegreeConstraints(bool b)
Switch usage of degree constraints (like indeg <= 1) on or off.
double upperBound() const
Returns the value of the global upper bound.
Definition: master.h:1530
BranchRule * branchRule() const
Returns a pointer to the branching rule of the subproblem.
Definition: sub.h:355
double coefficient() const
objective function coefficient
void incNrCutsTotal()
increases the number of separated directed cuts by 1
OSISOLVER
This enumeration defines which solvers can be used to solve the LP-relaxations.
Definition: master.h:209
Sub(abacus::Master *master)
Constructor for the root problem of the b&b tree.
int nNodes() const
number of nodes of the graph
virtual void terminateOptimization() override
store solution in EdgeArray
EdgeVariable * getVarTwin(edge e) const
returns the variable assigned to the twin of edge e
int maxNrAddedCuttingPlanes() const
maximum nr of cutting planes
Includes declaration of graph class.
STATUS status() const
Returns the status of the Master.
Definition: master.h:473
Constraint for nodes, e.g., in/outdegree stuff.
bool is_lout(Level level=Level::Default) const
returns true if such an lout command will result in text being printed
Definition: Logger.h:137
bool isSelfLoop() const
Definition: Graph_d.h:337
Centralized global and local logging facility working on streams like cout.
Definition: Logger.h:99
Level
supported log-levels from lowest to highest importance
Definition: Logger.h:103
EdgeWeightedGraph< double > & weightedGraphPH()
Subproblem of Steiner tree algorithm.
TYPE
The enumeration with the different variable types.
Definition: vartype.h:47
double coeff(const abacus::Variable *v) const override
coefficient of variable in constraint
StopwatchWallClock m_primalHeuristicTimer
timer for primal heuristics
edge edgeGToWgPH(edge e) const
edge mapping m_pGraph -> m_pWeightedGraphPH
node m_rootPH
root node in m_pWeightedGraphPH
void setSeparationStrategy(int b)
Set separation strategy for nested cuts.
StopwatchWallClock * primalHeuristicTimer()
timer for primal heuristics
const List< node > & terminalsList() const
list of terminals
int size() const
Returns the number of elements in the list.
Definition: List.h:1255
int nLp() const
Returns the number of optimized linear programs (only LP-relaxations).
Definition: master.h:509
StopwatchWallClock * separationTimer()
timer for separation
void readParameters(const string &fileName)
Opens the parameter file fileName, reads all parameters, and inserts them in the parameter table...
static const char * STATUS_[]
Literal values for the enumerators of the corresponding enumeration type.
Definition: master.h:99
Constraint * constraint(int i) const
Returns a pointer to the i-th active constraint.
Definition: sub.h:1858
virtual bool call(const Graph &graph, const EdgeArray< TCost > &weight, node s, node t, List< edge > &edgeList, edge e_st) override
The actual algorithm call.
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:325
Master(const EdgeWeightedGraph< T > &wG, const List< node > &terminals, const NodeArray< bool > &isTerminal, double eps, bool relaxed=false)
Constructor of the master problem.
int m_nIterRoot
statistics: nr of iterations in the root node of the b&b tree
bool isInBackCut(const node v) const
Returns whether this node is part of the back cut.
virtual double coeff(const Variable *v) const =0
Returns the coefficient of the variable v in the constraint.
void setPrimalHeuristic(MinSteinerTreeModule< double > *pMinSteinerTreeModule)
Set the module option for the primal heuristic.
Master * master_
A pointer to the corresponding master of the optimization.
Definition: sub.h:1436
abacus::NonDuplPool< abacus::Constraint, abacus::Variable > * m_pCutPool
the non-duplicate cut pool for the directed Steiner cuts
The namespace for all OGDF objects.
double coeff(const abacus::Variable *v) const override
coefficient of variable in constraint
bool m_shuffleTerminals
parameter: shuffle the list of terminals right before separation
open subproblems.
static const char * BRANCHINGSTRAT_[]
Literal values for the enumerators of the corresponding enumeration type.
Definition: master.h:130
EdgeArray< edge > m_twin
the twin edges (u,v) <-> (v,u)
virtual abacus::Sub * firstSub() override
generates the first subproblem
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition: Graph_d.h:578
Variable * variable(int i) const
Returns a pointer to the i-th active variable.
Definition: sub.h:1863
node newNode()
Creates a new node and returns it.
ENUMSTRAT enumerationStrategy() const
Returns the enumeration strategy.
Definition: master.h:342
LpSub * lp_
A pointer to the corresponding linear program.
Definition: sub.h:1448
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:545
void updateBestSolution(double *values)
updates best found solution
const Sub * father() const
Returns a pointer to the father of the subproblem in the branch-and-bound tree.
Definition: sub.h:198
void setConfigFile(const char *filename)
Set the config file to use that overrides all other settings.
void setNIterRoot(int val)
nr of iterations in the root node
int nIter_
The number of iterations in the cutting plane phase.
Definition: sub.h:1479
int m_callPrimalHeuristic
Strategy for primal heuristic (PH) calls.
unsigned hashKey() const override
retuns an hashkey for the cut; required method for nonduplpool
int edgeID(edge e) const
edge -> id of lp variable
bool empty() const
Returns true iff the list is empty.
Definition: List.h:236
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:112
Computes a max flow via Preflow-Push (global relabeling and gap relabeling heuristic).
const NodeArray< int > & nodeIDs() const
lp variable ids of nodes
void checkSetMaxPoolSize()
checks if current pool size is maximum and sets it if necessary
static std::ostream & ilout(Level l=Level::Default)
Definition: Logger.h:189
void setEpsilon(double eps)
Set the epsilon for the LP.
const Graph & graph() const
the directed graph, i.e., the bidirection of the input graph
virtual double coeff(const abacus::Variable *v) const override
coefficient of variable in constraint
Master * master()
Returns the master of the optimization.
Definition: sub.h:320
void useGSEC2Constraints(bool b)
Switch usage of constraints x_uv + x_vu <= 1 on or off.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
Master * m_pMaster
the master problem of the b&c algorithm
EdgeWeightedGraph< double > * m_pWeightedGraphPH
edge weighted bidirected graph; used and modified for primal heuristics
int m_callPrimalHeuristic
parameter: primal heuristic (PH) call strategy
Declaration of min-st-cut algorithms parameterized by max-flow alorithm.
int m_saturationStrategy
parameter: saturation strategy, only important if nested cuts are computed
Constraint for edges, e.g., subtour elimination constraints of size 2 ((G)SEC2)