/**
* @file tests/boost_graph/partitioning/gggp.cpp
* @author The PARADEVS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* PARADEVS - the multimodeling and simulation environment
* This file is a part of the PARADEVS environment
*
* Copyright (C) 2013 ULCO http://www.univ-litoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
namespace paradevs { namespace tests { namespace boost_graph {
extern UnorientedGraph::vertex_iterator vertexIt, vertexEnd;
extern UnorientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
extern OrientedGraph::vertex_iterator vertexIto, vertexEndo;
extern OrientedGraph::adjacency_iterator neighbourIto, neighbourEndo;
void ggp(UnorientedGraph *g, Entiers *sommetsSource,
Entiers *sommetsDestination, EntiersEntiers &Partition, int rand, int distance)
{
//std::cout<<""<size()==1){
//val=0;
//std::cout<<"Entré dans le debug ! "<size());
}
uint tmp=*max_element(tailles.begin(),tailles.end());
for(uint i=0; isize()==tmp)
{
ggp(g, Partition[i], sommetsDestination, Partition, rand_fini(0,Partition.at(i)->size()),
distance);
return;
}
}
}
// else
// val=rand_fini(0,sommetsSource->size()-1);//Tirage aléatoire de l'indice du premier sommet entre 0 et taille du tableau -1
//std::cout<<"val : "<at(val)<size();i++){
poids_max+=(*g)[sommetsSource->at(i)]._weight;
}
poids_max/=2.;
double poids;
if(distance == -1){
poids=(*g)[sommetsSource->at(rand)]._weight;
sommetsDestination->push_back(sommetsSource->at(rand));
sommetsSource->erase(sommetsSource->begin() + rand);
}else{
poids=(*g)[rand]._weight;
sommetsDestination->push_back(rand);
suprim_val(*sommetsSource,rand);
}
int cpt = 0;
// std::cout<<"taille sommetsSource avant le while : "<size()<size()>1)
{
//std::cout<<"taille sommetsSource dans le while "<size()<size() )
adjacence_ggp(sommetsDestination->at(cpt),sommets_adj,g);
else{
int val=rand_fini(0,sommetsSource->size()-1);
sommetsDestination->push_back(sommetsSource->at(val));
sommetsSource->erase(sommetsSource->begin() + val);
adjacence_ggp(sommetsDestination->at(cpt),sommets_adj,g);
}
/*std::cout<<"adj :"<size();i++)
{
for (uint j=0; jsize();j++)
{
remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
}
}*/
sort(sommetsDestination->begin(), sommetsDestination->end());
return;
}
else{
for(uint i =0; isize()!=1){
sommetsDestination->push_back(sommets_adj.at(i));
poids+=(*g)[sommets_adj.at(i)]._weight;
suprim_val(*sommetsSource, sommets_adj[i]);
}
if(poids>poids_max || sommetsSource->size()==1)
break;
}
/*std::cout<<"Sommets_source :"<size();i++){
std::cout<at(i)<<",";
}
std::cout<size();i++){
std::cout<at(i)<<",";
}
std::cout<poids_max || sommetsSource->size()==1){
/*for (uint i=0; isize();i++)
{
for (uint j=0; jsize();j++)
{
remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
}
}*/
sort(sommetsDestination->begin(), sommetsDestination->end());
return;
}
sommets_adj.clear();
cpt++;
}
}
/*for (uint i=0; isize();i++)
{
for (uint j=0; jsize();j++)
{
remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
}
}*/
sort(sommetsDestination->begin(), sommetsDestination->end());
}
void Iter_2l(EntiersEntiers &part, int nbr_parties, UnorientedGraph *g,
const std::string &nom_cut, int nbr_tirage, const std::string &nom_strat, int distance)
{
for(int i = 0; isize() > Partition.at(i)->size())
Partition.at(i)->swap(**it1);
}
}
for(int j = 0; jsize()==1){
Entiers tailles;
for(uint i=0;isize());
}
uint tmp=*max_element(tailles.begin(),tailles.end());
for(uint i=0; isize()==tmp)
{
gggp_pond(g,Partition[i],sommetsDestination,Partition,rand_fini(0,Partition.at(i)->size()),distance);
return;
}
}
}
double poids_max=0;
for(uint i=0;isize();i++){
poids_max+=(*g)[sommetsSource->at(i)]._weight;
}
poids_max/=2.;
double poids;
std::vector sommets_cut;
float cut;
if(distance == -1){
poids=(*g)[sommetsSource->at(rand)]._weight;
cut = Degree(*g,sommetsSource->at(rand));
//std::cout<<"verif rand : "<push_back(sommetsSource->at(rand));
sommetsSource->erase(sommetsSource->begin() + rand);
}else{
poids=(*g)[rand]._weight;
cut = Degree(*g,rand);
sommetsDestination->push_back(rand);
suprim_val(*sommetsSource,rand);
}
while(poidssize()>1)
{
Liste_Voisin(*sommetsDestination,sommets_adj,*g);
if(sommets_adj.size()==0)
{
for (uint i=0; isize();i++)
{
for (uint j=0; jsize();j++)
{
remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
}
}
sort(sommetsDestination->begin(), sommetsDestination->end());
return;
}
else{
sort(sommets_adj.begin(), sommets_adj.end());
for(uint i=0;ipush_back(sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
poids+=(*g)[sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]]._weight;
suprim_val(*sommetsSource, sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
suprim_val(sommets_adj, sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
sommets_cut.clear();
}
}
sort(sommetsDestination->begin(), sommetsDestination->end());
/*for (uint i=0; isize();i++)
{
for (uint j=0; jsize();j++)
{
remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
}
}*/
}
// void gggp_pond(UnorientedGraph *g, Entiers *sommetsSource,
// Entiers *sommetsDestination, EntiersEntiers &Partition)
// {
// int val;
// Entiers sommets_adj;
// if(sommetsSource->size()==1){
// val=0;
// //std::cout<<"Entré dans le debug ! "<size());
// }
// uint tmp=*max_element(tailles.begin(),tailles.end());
// for(uint i=0; isize()==tmp)
// {
// gggp_pond(g,Partition[i],sommetsDestination,Partition);
// return;
// }
// }
// }
// else
// val=rand_fini(0,sommetsSource->size()-1);//Tirage aléatoire de l'indice du premier sommet entre 0 et taille du tableau -1
// //std::cout<<"val : "<at(val)<size();i++){
// poids_max+=(*g)[sommetsSource->at(i)]._weight;
// }
// poids_max/=2.;
// double poids=(*g)[sommetsSource->at(val)]._weight;
// std::vector sommets_cut;
// float cut = Degree(*g,sommetsSource->at(val));
// sommetsDestination->push_back(sommetsSource->at(val));
// sommetsSource->erase(sommetsSource->begin() + val);
// // std::cout<<"taille sommetsSource avant le while : "<size()<size()>1)
// {
// //std::cout<<"taille sommetsSource dans le while "<size()<size();i++)
// {
// for (uint j=0; jsize();j++)
// {
// remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
// }
// }
// sort(sommetsDestination->begin(), sommetsDestination->end());
// return;
// }
// else{
// sort(sommets_adj.begin(), sommets_adj.end());
// /*std::cout<<"adj :"<push_back(sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
// //std::cout<<"Sommet deplacé : "<size();i++){
// std::cout<at(i)<<",";
// }
// std::cout<size();i++){
// std::cout<at(i)<<",";
// }
// std::cout<size();i++)
// {
// for (uint j=0; jsize();j++)
// {
// remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
// }
// }
// sort(sommetsDestination->begin(), sommetsDestination->end());
// //std::cout<<"fin du gggp_pond"<size() > Partition.at(i)->size())
// Partition.at(i)->swap(**it1);
// }
// }
// for(int j = 0; jsize(); j++){
// // std::cout<at(j)<<" ";
// // }
// // std::cout<<"\n"<size();
uint cpt_sommets=1;
int val;
uint cpt;
if(nbr_parties==size){
for(uint i = 0; i < nbr_parties;i++){
if(Partition.at(0)->size()!=1)
{
val=rand_fini(0,Partition.at(0)->size()-1);//tirage aléatoire d'un sommets
}
else
val=0;
int vertex = Partition.at(0)->at(val);
Entiers *part = new Entiers();
part->push_back(vertex);// ajout du sommet tiré
suprim_val(*Partition.at(0),vertex);//suppression du sommet dans la premiere partie
}
}
/*
* Boucle sur le nombre de partie à réaliser
*/
for(uint i = 0; i < nbr_parties-1;i++){
if(Partition.at(0)->size()!=1)
{
val=rand_fini(0,Partition.at(0)->size()-1);//tirage aléatoire d'un sommets
}
else
val=0;
int vertex = Partition.at(0)->at(val);
/*
* Initialisation d'un pointeur sur un vecteur d'entier, dans notre cas
* la n+1 ième partie de la partition
*/
Entiers *part = new Entiers();
part->push_back(vertex);// ajout du sommet tiré
suprim_val(*Partition.at(0),vertex);//suppression du sommet dans la premiere partie
cpt=1;
/*
* Pour chaque element de la nouvelle partie faire
*/
for(uint j = 0; jsize();j++){
/*
* Détermination des voisins de chacun des sommets de cette nouvelle
* partie et ajoue de ce voisin si celui-ci est présent dans la première partie (Partition[0])
*/
tie(neighbourIt, neighbourEnd) = adjacent_vertices(part->at(j),*g);
for (; neighbourIt != neighbourEnd; ++neighbourIt){
if(In_tab(*Partition.at(0),*neighbourIt)==1){
// std::cout<<"le voisin déplacé est : "<<*neighbourIt<push_back(*neighbourIt);
cpt_sommets++;
suprim_val(*Partition.at(0),*neighbourIt);
cpt++;
}
/*
* Si le nombre moyen de sommets est atteind dans la partie on sort de la boucle des voisins
* Même chose si l'on a rencontré le nombre total de sommets
*/
if(cpt==(size/nbr_parties)+1)
break;
if(cpt_sommets==size)
break;
}
/*
* Même chose
*/
if(cpt==(size/nbr_parties)+1)
break;
if(cpt_sommets==size)
break;
}
Partition.push_back(part);// ajoue de la nouvelle partie à la partition
if(cpt_sommets==size)
break;
}
}
EntiersEntiers Random_partitioning(UnorientedGraph *g,
uint nbr_parties)
{
EntiersEntiers Partition;
Entiers random_order; //gestion d'un tableau contenant tout les sommets et ranger de façon aléatoire
for (uint i=0 ; ipush_back(random_order.at(i));
}
Partition.push_back(part);
}
Entiers *part = new Entiers();
for(uint i = (nbr_parties-1)*size; i < random_order.size(); i++){
part->push_back(random_order.at(i));
}
Partition.push_back(part);
for(uint i = 0 ; i < Partition.size() ; i++){
sort(Partition.at(i)->begin(),Partition.at(i)->end());
}
return Partition;
}
OrientedGraphs Multiniveau(uint niveau_contraction,
UnorientedGraph *g,
UnorientedGraph *graph_origin,
OrientedGraph *go,
int nbr_parties,
int nbr_tirage,
std::string contraction,
std::string type_methode,
std::string choix_affinage,
std::string type_cut,
Edges& /* edge_partie */,
OutputEdgeList& outputedgelist,
InputEdgeList& inputedgelist,
Connections& connections,
std::vector &Cut, int distance)
{
EntiersEntiers Partition;
Entiers *part = new Entiers();
Base_Graph baseg;
baseg.push_back(g);
ListEntiersEntiers liste_corr;
uint cpt =0;
int val_cpt = num_vertices(*g);
bool stop = false;
if (niveau_contraction == val_cpt) {
stop = true;
}
while(stop != true)
{
if(contraction == "HEM")
stop = contraction_HEM(baseg.at(cpt),baseg,liste_corr,niveau_contraction,val_cpt);
else
stop = contraction_Random_Maching(baseg.at(cpt),baseg,liste_corr,niveau_contraction,val_cpt);
cpt++;
}
for(int i = 0; ipush_back(i);
}
Partition.push_back(part);
UnorientedGraph copy_graph;
boost::copy_graph(*baseg.at(baseg.size()-1),copy_graph);
// std::cout<<"Graphe contracté : "< color;
color.push_back("[color=blue2, fontcolor=blue2];");
color.push_back("[color=red, fontcolor=red];");
color.push_back("[color=green, fontcolor=green];");
color.push_back("[color=yellow, fontcolor=yellow2];");
color.push_back("[color=saddlebrown, fontcolor=saddlebrown];");
color.push_back("[color=turquoise, fontcolor=turquoise];");
color.push_back("[color=orange, fontcolor=orange];");
color.push_back("[color=olivedrab, fontcolor=olivedrab];");
color.push_back("[color=indigo, fontcolor=indigo];");
color.push_back("[color=gold, fontcolor=gold];");
color.push_back("[color=slateblue2, fontcolor=slateblue2];");
color.push_back("[color=dimgrey, fontcolor=dimgrey];");
color.push_back("[color=cyan, fontcolor=cyan];");
color.push_back("[color=purple1, fontcolor=purpule1];");
color.push_back("[color=crimson, fontcolor=crimson];");
color.push_back("[color=black, fontcolor=black];");
/*std::ofstream fichier2 ("../../sortie_graphe/graph_partition_38_4_1.txt", std::ios::out);
fichier2<<"digraph G {"< {";
tie(neighbourIto, neighbourEndo) = adjacent_vertices(*vertexIto,
*go);
for (; neighbourIto != neighbourEndo; ++neighbourIto){
fichier2<<(*go)[*neighbourIto]._index<<";";
}
fichier2<<"}"<size(); j++)
{
fichier2<at(j)<begin(); it1 != (*it)->end(); it1++)
{
delete *it1;
*it1 = NULL;
}
delete *it;
*it = NULL;
}
for(Base_Graph::iterator it = baseg.begin(); it != baseg.end(); it++)
{
delete *it;
*it = NULL;
}
return Graphes;
}
void Optimisation_method_neighbour(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition, int nbr_tirage, const std::string &name_cut, const std::string &name_strat){
/*Initialisation des parametres*/
//UnorientedGraph *copy_g_ref = new UnorientedGraph();
Entiers *part2_cons = new Entiers();
Entiers *part_cour_cons = new Entiers();
Entiers Random_list_vertices;
double cut=1000000000.;
//boost::copy_graph(*g,*copy_g_ref);
for (int i=0 ; isize() ; i++)
Random_list_vertices.push_back(i);
for (int j=0 ; jsize()-1 ; j++) {
int rand_pos = rand()%(Partition.at(index_partition)->size()-j)+j;
int tmp = Random_list_vertices[j];
Random_list_vertices[j] = Random_list_vertices[rand_pos];
Random_list_vertices[rand_pos] = tmp;
}
if(Partition.at(index_partition)->size()< nbr_tirage)
nbr_tirage = Partition.at(index_partition)->size();
/*Boucle de conservation de la meilleure bissection*/
for(int k = 0; ksize();t++){
tmp_part->push_back(Partition.at(index_partition)->at(t));
}
/*std::cout<<"Ensembles verification !!! "<size(); i++){
std::cout<at(i)<<" ";
}
std::cout<size(); j++){
std::cout<at(j)<<" ";
}
std::cout<size(); i++){
std::cout<at(i)<<" ";
}
std::cout<size(); j++){
std::cout<at(j)<<" ";
}
std::cout<size();i++)
{
for (uint j=0; jsize();j++)
{
remove_edge(part_cour_cons->at(i),part2_cons->at(j),*g);
}
}
/*Modification des informations*/
Partition.at(index_partition)=part_cour_cons;
Partition.push_back(part2_cons);
//g=copy_g_ref;
}
void Optimisation_method_neighbour_distance(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition, int nbr_tirage, int distance,
const std::string &name_cut, const std::string &name_strat){
//Initialisation des parametres
Entiers *part2_cons = new Entiers();
Entiers *part_cour_cons = new Entiers();
double cut=1000000000.;
int val;
std::list vertex_list;
for(int verx =0; verxsize(); verx++){
vertex_list.push_back(Partition.at(index_partition)->at(verx));
}
/*std::list::iterator toto;
for(toto = vertex_list.begin(); toto != vertex_list.end(); toto ++)
std::cout<<*toto<<" ";
std::cout<size()< nbr_tirage)
nbr_tirage = Partition.at(index_partition)->size();
//Boucle de conservation de la meilleure bissection
for(int k = 0; k::iterator Iter;
if(vertex_list.size()!=0){
//std::cout<<"Il reste des sommets à tirer"<size();t++){
tmp_part->push_back(Partition.at(index_partition)->at(t));
}
//std::cout<<"Sommet tirée avant entré dans gggp : "<<*Iter<size(); alpha ++){
std::cout<at(alpha)<<" ";
}
std::cout<size(); alpho ++){
std::cout<at(alpho)<<" ";
}
std::cout<size();i++)
{
for (uint j=0; jsize();j++)
{
remove_edge(part_cour_cons->at(i),part2_cons->at(j),*g);
}
}
//Modification des informations
Partition.at(index_partition)=part_cour_cons;
Partition.push_back(part2_cons);
/*std::cout< &vertex_list, int distance){
std::vector > vertex_delete;
std::list liste1;
std::list vd;
liste1.push_back(tirage); /*modif*/
vertex_delete.push_back(liste1);
for(int i=0; i liste_tmp;
std::list::iterator Ite_tmp;
for(Ite_tmp = vertex_delete.at(i).begin(); Ite_tmp != vertex_delete.at(i).end(); Ite_tmp ++){
tie(neighbourIt, neighbourEnd) = adjacent_vertices(*Ite_tmp,*g);
for (; neighbourIt != neighbourEnd; ++neighbourIt){
liste_tmp.push_back(*neighbourIt);/*modif*/
}
}
liste_tmp.sort();
liste_tmp.unique();
vertex_delete.push_back(liste_tmp);
}
//std::cout<::iterator Ite_tmp;
for(Ite_tmp = vertex_delete.at(i).begin(); Ite_tmp != vertex_delete.at(i).end(); Ite_tmp ++){
std::cout<<*Ite_tmp<<" ";
}
std::cout<::iterator Ite_tmp;
for(Ite_tmp = vd.begin(); Ite_tmp != vd.end(); Ite_tmp ++){
std::cout<<*Ite_tmp<<" ";
}
std::cout<::iterator Ite;
for(Ite = vd.begin(); Ite != vd.end(); Ite ++){
vertex_list.remove(*Ite);
}
}
} } } // namespace paradevs tests boost_graph