COIN-OR::LEMON - Graph Library

source: glemon-0.x/kruskalbox.cc @ 176:9fc3d5170b24

Last change on this file since 176:9fc3d5170b24 was 174:95872af46fc4, checked in by Alpar Juttner, 17 years ago

Add copyright headers

File size: 2.1 KB
Line 
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
19#include <kruskalbox.h>
20
21enum {INPUT, OUTPUT, MAP_NUM};
22
23KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
24{
25  init(t);
26}
27   
28void KruskalBox::run()
29{
30  if(
31     tabcbt.get_active_text()!="" &&
32     (edgemapcbts[INPUT])->get_active_text()!="" &&
33     (edgemapcbts[OUTPUT])->get_active_text()!=""
34     )
35    {
36
37      const Graph &g=mapstorage->graph;
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);
42
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        }
56
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());
66 
67    }
68}
69   
70void KruskalBox::build_box()
71{
72  std::vector<std::string> empty_vector;
73
74  addMapSelector("Edgecosts: ", true);
75  addMapSelector("Edges of tree here: ", true);
76
77  resultlabel.set_text("Result: algorithm is not run yet.");
78  pack_start(resultlabel);
79}
Note: See TracBrowser for help on using the repository browser.