[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 | |
---|
[106] | 19 | #include <kruskalbox.h> |
---|
| 20 | |
---|
[109] | 21 | enum {INPUT, OUTPUT, MAP_NUM}; |
---|
| 22 | |
---|
[108] | 23 | KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox() |
---|
[106] | 24 | { |
---|
[108] | 25 | init(t); |
---|
[106] | 26 | } |
---|
| 27 | |
---|
| 28 | void KruskalBox::run() |
---|
| 29 | { |
---|
[114] | 30 | if( |
---|
| 31 | tabcbt.get_active_text()!="" && |
---|
| 32 | (edgemapcbts[INPUT])->get_active_text()!="" && |
---|
| 33 | (edgemapcbts[OUTPUT])->get_active_text()!="" |
---|
| 34 | ) |
---|
| 35 | { |
---|
[109] | 36 | |
---|
[145] | 37 | const Graph &g=mapstorage->graph; |
---|
[114] | 38 | Graph::EdgeMap<double> * inputmap= |
---|
| 39 | ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]); |
---|
| 40 | Graph::EdgeMap<bool> outputmap(g); |
---|
| 41 | double res=kruskal(g, *inputmap, outputmap); |
---|
[109] | 42 | |
---|
[114] | 43 | for (EdgeIt i(g); i!=INVALID; ++i) |
---|
| 44 | { |
---|
| 45 | if(outputmap[i]) |
---|
| 46 | { |
---|
| 47 | (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> |
---|
| 48 | get_active_text()]))[i]=1; |
---|
| 49 | } |
---|
| 50 | else |
---|
| 51 | { |
---|
| 52 | (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> |
---|
| 53 | get_active_text()]))[i]=0; |
---|
| 54 | } |
---|
| 55 | } |
---|
[111] | 56 | |
---|
[114] | 57 | std::ostringstream o; |
---|
| 58 | o << "Result: " << res; |
---|
| 59 | resultlabel.set_text(o.str()); |
---|
| 60 | |
---|
| 61 | mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); |
---|
| 62 | // mapstorage->changeActiveMap(true, E_COLOR, |
---|
| 63 | // (edgemapcbts[OUTPUT])->get_active_text()); |
---|
| 64 | // mapstorage->changeActiveMap(true, E_TEXT, |
---|
| 65 | // (edgemapcbts[INPUT])->get_active_text()); |
---|
[110] | 66 | |
---|
[114] | 67 | } |
---|
[106] | 68 | } |
---|
| 69 | |
---|
| 70 | void KruskalBox::build_box() |
---|
| 71 | { |
---|
[114] | 72 | std::vector<std::string> empty_vector; |
---|
| 73 | |
---|
[116] | 74 | addMapSelector("Edgecosts: ", true); |
---|
| 75 | addMapSelector("Edges of tree here: ", true); |
---|
[109] | 76 | |
---|
| 77 | resultlabel.set_text("Result: algorithm is not run yet."); |
---|
| 78 | pack_start(resultlabel); |
---|
[106] | 79 | } |
---|