Added this in order to prevent losing it.
authorladanyi
Mon, 29 Nov 2004 16:11:51 +0000
changeset 102428e117c5bddf
parent 1023 3268fef5d623
child 1025 3b1ad8bc21da
Added this in order to prevent losing it.
src/work/akos/k_cover.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/akos/k_cover.cc	Mon Nov 29 16:11:51 2004 +0000
     1.3 @@ -0,0 +1,58 @@
     1.4 +#include <lemon/list_graph.h>
     1.5 +
     1.6 +using namespace lemon;
     1.7 +
     1.8 +typedef ListGraph Graph;
     1.9 +typedef Graph::NodeIt NodeIt;
    1.10 +typedef Graph::EdgeIt EdgeIt;
    1.11 +
    1.12 +class MyEntity {
    1.13 +public:
    1.14 +  Graph &g;
    1.15 +  Graph::NodeMap<bool> selected;
    1.16 +  int edges;
    1.17 +  int covered_edges;
    1.18 +
    1.19 +  MyEntity(Graph &_g) : g(_g), selected(_g) {}
    1.20 +  MyEntity(MyEntity& e) : g(e.g), selected(e.g) {
    1.21 +    for (NodeIt n(g); n != INVALID; ++n) {
    1.22 +      selected[n] = e.selected[n];
    1.23 +    }
    1.24 +    edges = e.edges;
    1.25 +    covered_edges = e.covered_edges;
    1.26 +  }
    1.27 +  double getCost() {
    1.28 +    return (double) (edges - covered_edges);
    1.29 +  }
    1.30 +  void mutate() {
    1.31 +  
    1.32 +  }
    1.33 +  void revert() {
    1.34 +  
    1.35 +  }
    1.36 +};
    1.37 +
    1.38 +int main() {
    1.39 +  Graph g;
    1.40 +  // beolvasas
    1.41 +  MyEntity ent(g);
    1.42 +
    1.43 +  // kezdeti lefedes generalasa
    1.44 +  int nn = 0;
    1.45 +  for (NodeIt n(g); n != INVALID; ++n) {
    1.46 +    ent.selected[n] = false;
    1.47 +    nn++;
    1.48 +  }
    1.49 +  // k db random node kivalasztasa
    1.50 +
    1.51 +  int i = 0, j = 0;
    1.52 +  for (EdgeIt e(g); e != INVALID; ++e) {
    1.53 +    i++;
    1.54 +    if ((ent.selected[g.source(e)]) || (ent.selected[g.target(e)])) {
    1.55 +      j++;
    1.56 +    }
    1.57 +  }
    1.58 +  ent.edges = i;
    1.59 +  ent.covered_edges = j;
    1.60 +
    1.61 +}