[174] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[194] | 19 | #include <lemon/kruskal.h> |
---|
| 20 | |
---|
| 21 | #include <mapstorage.h> |
---|
| 22 | #include <mapselector.h> |
---|
| 23 | #include <algobox.h> |
---|
[106] | 24 | #include <kruskalbox.h> |
---|
| 25 | |
---|
[109] | 26 | enum {INPUT, OUTPUT, MAP_NUM}; |
---|
| 27 | |
---|
[108] | 28 | KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox() |
---|
[106] | 29 | { |
---|
[108] | 30 | init(t); |
---|
[106] | 31 | } |
---|
| 32 | |
---|
| 33 | void KruskalBox::run() |
---|
| 34 | { |
---|
[114] | 35 | if( |
---|
| 36 | tabcbt.get_active_text()!="" && |
---|
| 37 | (edgemapcbts[INPUT])->get_active_text()!="" && |
---|
| 38 | (edgemapcbts[OUTPUT])->get_active_text()!="" |
---|
| 39 | ) |
---|
| 40 | { |
---|
[109] | 41 | |
---|
[145] | 42 | const Graph &g=mapstorage->graph; |
---|
[114] | 43 | Graph::EdgeMap<double> * inputmap= |
---|
| 44 | ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]); |
---|
| 45 | Graph::EdgeMap<bool> outputmap(g); |
---|
| 46 | double res=kruskal(g, *inputmap, outputmap); |
---|
[109] | 47 | |
---|
[114] | 48 | for (EdgeIt i(g); i!=INVALID; ++i) |
---|
| 49 | { |
---|
| 50 | if(outputmap[i]) |
---|
| 51 | { |
---|
| 52 | (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> |
---|
| 53 | get_active_text()]))[i]=1; |
---|
| 54 | } |
---|
| 55 | else |
---|
| 56 | { |
---|
| 57 | (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> |
---|
| 58 | get_active_text()]))[i]=0; |
---|
| 59 | } |
---|
| 60 | } |
---|
[111] | 61 | |
---|
[114] | 62 | std::ostringstream o; |
---|
| 63 | o << "Result: " << res; |
---|
| 64 | resultlabel.set_text(o.str()); |
---|
| 65 | |
---|
| 66 | mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); |
---|
| 67 | // mapstorage->changeActiveMap(true, E_COLOR, |
---|
| 68 | // (edgemapcbts[OUTPUT])->get_active_text()); |
---|
| 69 | // mapstorage->changeActiveMap(true, E_TEXT, |
---|
| 70 | // (edgemapcbts[INPUT])->get_active_text()); |
---|
[110] | 71 | |
---|
[114] | 72 | } |
---|
[106] | 73 | } |
---|
| 74 | |
---|
| 75 | void KruskalBox::build_box() |
---|
| 76 | { |
---|
[114] | 77 | std::vector<std::string> empty_vector; |
---|
| 78 | |
---|
[116] | 79 | addMapSelector("Edgecosts: ", true); |
---|
| 80 | addMapSelector("Edges of tree here: ", true); |
---|
[109] | 81 | |
---|
| 82 | resultlabel.set_text("Result: algorithm is not run yet."); |
---|
| 83 | pack_start(resultlabel); |
---|
[106] | 84 | } |
---|