Skip to content
Snippets Groups Projects
Commit 1bb6cff4 authored by Florian Heinrichs's avatar Florian Heinrichs
Browse files

first things for greedy packing - not finished yet

parent f4cc9594
Branches
1 merge request!8Resolve "Greedy Packing"
......@@ -58,7 +58,9 @@ unsigned int solver::get_lower(){
return pr.get_max_flow();
}
else if(lb_algorithm_ == lb::gp){
auto g_p = greedy_packing(graph_, sources, sinks);
g_p.run();
return g_p.get_max_flow();
}
return partition_.current_objective();
}
......
#include <gp-bnb/greedy_packing.hpp>
#include <iostream>
greedy_packing::greedy_packing(const graph& g, std::vector<node_id> a, std::vector<node_id> b)
: graph_(g), a(a), b(b) {
};
//breadth-first-search to determine neighbors of B
void greedy_packing::bfs(){
x.resize(graph_.num_nodes() - (a.size() + b.size()));
std::vector<bool> visited(graph_.num_nodes() +1, false);
for(node_id node : b){
q.push(node);
visited[node] = true;
}
for(node_id node: a){
visited[node] = true;
}
unsigned int last_node = b.size();
unsigned int count = 0;
while(!q.empty()){
node_id node = q.front();
q.pop();
std::vector<node_id> neighbors = graph_.get_adjacency(node);
for(node_id v : neighbors){
if(v == last_node)
end_of_neighbors = count;
if(visited[v] == false){
q.push(v);
x[count++] = v;
}
visited[v] = true;
}
}
return;
};
void greedy_packing::run(){
//x konstruieren: enthält alle unpartitionierten knoten
//zuerst die nachbarn von b bis zum index end_of_neighbors
//ab end_of_neighbors +1 kommen alle anderen unpartitionierten knoten
bfs();
/*
std::cerr << x.size() << std::endl;
for(int i = 0; i < x.size(); i++){
std::cerr << x[i] << " ";
}
std::cerr << " end_of_neighbors: " << end_of_neighbors << std::endl;
*/
//P konstruieren
//dafür für jeden nachbarn von B einen eigenen Block
//dann jeweils kleinsten block um einen nachbarn erweitern
//danach lokale suche um balance zu verbessern
//knoten aus x die in keinem block von P sind sind unerreichbar von B
partitioning.resize(end_of_neighbors+1);
for(unsigned int i = 0; i <= end_of_neighbors; i++){
partitioning[i].push_back(x[i]);
}
//füge von B unerreichbar knoten zu a hinzu (sind die knoten die
//bei konstruktion von P "übrig bleiben")
//danach füge Knoten aus größtem Block hinzu bis A* < n/2
/*while(a_count < graph_.num_nodes()/2){
}
*/
return;
};
......@@ -9,6 +9,7 @@
#include <gp-bnb/edmonds_karp.hpp>
#include <gp-bnb/incremental_bfs.hpp>
#include <gp-bnb/push_relabel.hpp>
#include <gp-bnb/greedy_packing.hpp>
namespace gp_bnb {
......
#ifndef GREEDYPACKING_H_
#define GREEDYPACKING_H_
#include <queue>
#include <vector>
#include <gp-bnb/graph.hpp>
class greedy_packing{
public:
greedy_packing(const graph& g, std::vector<node_id> a, std::vector<node_id> b);
void run();
int get_max_flow() const{
return flow_;
};
private:
void bfs();
const graph& graph_;
//end of neighbors determines index of x where the nodes
//aren't neighbors of B anymore
unsigned int a_count, end_of_neighbors;
//partial partition into blocks a and b
//x is block which starts with the neighbors of B
//following the other unpartitioned nodes
std::vector<node_id> a, b, x;
std::vector<std::vector<node_id>> partitioning;
int flow_;
std::queue<node_id> q;
};
#endif /* GREEDY_PACKING_H_ */
\ No newline at end of file
......@@ -17,6 +17,7 @@ executable('gp-bnb',
'bnb/ibfs_subtree.cpp',
'bnb/push_relabel.cpp',
'bnb/bnb.cpp',
'bnb/greedy_packing.cpp',
include_directories: inc)
......
......@@ -13,6 +13,7 @@ testexe = executable(
'../bnb/ibfs_subtree.cpp',
'../bnb/push_relabel.cpp',
'../bnb/bnb.cpp',
'../bnb/greedy_packing.cpp',
include_directories : inc) # declared include directories in root :code:`meson.build`
# test execution
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment