kruskalbox.cc
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Mon, 07 Jul 2008 15:20:43 +0100
changeset 3 2cc5ed6e6255
permissions -rw-r--r--
Use hg changeset hash instead of svn revision.
hegyi@1
     1
/* -*- C++ -*-
hegyi@1
     2
 *
hegyi@1
     3
 * This file is a part of LEMON, a generic C++ optimization library
hegyi@1
     4
 *
hegyi@1
     5
 * Copyright (C) 2003-2006
hegyi@1
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
hegyi@1
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
hegyi@1
     8
 *
hegyi@1
     9
 * Permission to use, modify and distribute this software is granted
hegyi@1
    10
 * provided that this copyright notice appears in all copies. For
hegyi@1
    11
 * precise terms see the accompanying LICENSE file.
hegyi@1
    12
 *
hegyi@1
    13
 * This software is provided "AS IS" with no warranty of any kind,
hegyi@1
    14
 * express or implied, and with no claim as to its suitability for any
hegyi@1
    15
 * purpose.
hegyi@1
    16
 *
hegyi@1
    17
 */
hegyi@1
    18
hegyi@1
    19
#include <lemon/kruskal.h>
hegyi@1
    20
hegyi@1
    21
#include <mapstorage.h>
hegyi@1
    22
#include <mapselector.h>
hegyi@1
    23
#include <algobox.h>
hegyi@1
    24
#include <kruskalbox.h>
hegyi@1
    25
hegyi@1
    26
enum {INPUT, OUTPUT, MAP_NUM};
hegyi@1
    27
hegyi@1
    28
KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
hegyi@1
    29
{
hegyi@1
    30
  init(t);
hegyi@1
    31
}
hegyi@1
    32
    
hegyi@1
    33
void KruskalBox::run()
hegyi@1
    34
{
hegyi@1
    35
  if(
hegyi@1
    36
      tabcbt.get_active_text()!="" &&
hegyi@1
    37
      (arcmapcbts[INPUT])->get_active_text()!="" &&
hegyi@1
    38
      (arcmapcbts[OUTPUT])->get_active_text()!=""
hegyi@1
    39
    )
hegyi@1
    40
  {
hegyi@1
    41
hegyi@1
    42
    const Digraph &g=mapstorage->getDigraph();
hegyi@1
    43
    std::string input_map_name = arcmapcbts[INPUT]->get_active_text();
hegyi@1
    44
    Digraph::ArcMap<bool> outputmap(g);
hegyi@1
    45
    const MapStorage::NumericArcMap& inputmap=
hegyi@1
    46
      mapstorage->getNumericArcMap(input_map_name);
hegyi@1
    47
    double res=kruskal(g, inputmap, outputmap);
hegyi@1
    48
hegyi@1
    49
    for (ArcIt i(g); i!=INVALID; ++i)
hegyi@1
    50
    {
hegyi@1
    51
      if(outputmap[i])
hegyi@1
    52
      {
hegyi@1
    53
        mapstorage->set(arcmapcbts[OUTPUT]->get_active_text(), i, 1.0);
hegyi@1
    54
      }
hegyi@1
    55
      else
hegyi@1
    56
      {
hegyi@1
    57
        mapstorage->set(arcmapcbts[OUTPUT]->get_active_text(), i, 0.0);
hegyi@1
    58
      }
hegyi@1
    59
    }
hegyi@1
    60
hegyi@1
    61
    std::ostringstream o;
hegyi@1
    62
    o << "Result: " << res;
hegyi@1
    63
    resultlabel.set_text(o.str());
hegyi@1
    64
hegyi@1
    65
    mapstorage->mapChanged(true, (arcmapcbts[OUTPUT])->get_active_text());
hegyi@1
    66
    //   mapstorage->changeActiveMap(true, E_COLOR,
hegyi@1
    67
    // 			      (arcmapcbts[OUTPUT])->get_active_text());
hegyi@1
    68
    //   mapstorage->changeActiveMap(true, E_TEXT,
hegyi@1
    69
    // 			      (arcmapcbts[INPUT])->get_active_text());
hegyi@1
    70
hegyi@1
    71
  }
hegyi@1
    72
}
hegyi@1
    73
    
hegyi@1
    74
void KruskalBox::build_box()
hegyi@1
    75
{
hegyi@1
    76
  std::vector<std::string> empty_vector;
hegyi@1
    77
hegyi@1
    78
  addMapSelector("Arccosts: ", true, NUM);
hegyi@1
    79
  addMapSelector("Arcs of tree here: ", true, NUM);
hegyi@1
    80
hegyi@1
    81
  resultlabel.set_text("Result: algorithm is not run yet.");
hegyi@1
    82
  pack_start(resultlabel);
hegyi@1
    83
}