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