GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
priority_graph.h
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
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-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
29#include <vector>
30#include <queue>
31#include <algorithm>
32#include <iostream>
33#include <set>
34
35using namespace std;
36
38 bool operator() (const pair<int, set<int> >& lhs, const pair<int, set<int> >& rhs){
39 return lhs.second.size() > rhs.second.size()
40 || (lhs.second.size() == rhs.second.size() && lhs.first > rhs.first);
41 }
42};
43
44class priority_graph : public priority_queue<pair<int, set<int> >, vector<pair<int, set<int> > >, Comparator >
45{
46private:
47 set<int> nodes; // for optimization reasons
48public:
49 void addEdge(int node_i, int node_j){
50 bool found1 = false;
51 bool found2 = false;
52 for(auto it = this->c.begin(); it < this->c.end(); ++it)
53 {
54 if(it->first == node_i){
55 it->second.insert(node_j);
56 found1 = true;
57 }
58 if(it->first == node_j){
59 it->second.insert(node_i);
60 found2 = true;
61 }
62 if(found1 && found2) break;
63 }
64 make_heap(this->c.begin(), this->c.end(), this->comp);
65 }
67 set<int> res;
68 for(auto it = this->c.begin(); it < this->c.end(); ++it){
69 if(it->first == node){
70 return it->second;
71 }
72 }
73 return res;
74 }
75 void addNode(int id){
76 auto res = nodes.insert(id);
77 if(res.second == true)
78 this->push(pair<int, set<int> >(id, set<int>()));
79 }
80 bool removeNode(int node, vector<int>& removed){
81 nodes.erase(node);
82 bool res;
83 auto it = this->c.begin();
84 for(; it < this->c.end(); ++it)
85 {
86 if(it->first == node){
87 break;
88 }
89 }
90 if (it != this->c.end()) {
91 this->c.erase(it);
92 make_heap(this->c.begin(), this->c.end(), this->comp);
93 removed.push_back(node);
94 res = true;
95 }
96 else{
97 cout << "failed to remove node " << node << endl;
98 return false;
99 }
100
101 it = this->c.begin();
102 for(; it < this->c.end(); ++it)
103 {
104 it->second.erase(node);
105 }
106
107 return res;
108 }
110 return nodes;
111 }
112};
void addNode(int id)
set< int > getNeighbors(int node)
set< int > getNodes()
bool removeNode(int node, vector< int > &removed)
void addEdge(int node_i, int node_j)
bool operator()(const pair< int, set< int > > &lhs, const pair< int, set< int > > &rhs)