demo/simann_maxcut_demo.cc
changeset 2379 248152674a9e
parent 1956 a055123339d5
child 2386 81b47fc5c444
equal deleted inserted replaced
1:365b0b782efd 2:6359fe45785c
    52     int sum;
    52     int sum;
    53     Node last_moved;
    53     Node last_moved;
    54     Entity(Graph& _g, Graph::EdgeMap<int>& _w) : g(_g), w(_w), a(_g) {}
    54     Entity(Graph& _g, Graph::EdgeMap<int>& _w) : g(_g), w(_w), a(_g) {}
    55     double mutate() {
    55     double mutate() {
    56       static const int node_num = countNodes(g);
    56       static const int node_num = countNodes(g);
    57       int i = 1 + (int) (node_num * (rand() / (RAND_MAX + 1.0)));
    57       int i = 1 + rnd[node_num];
    58       NodeIt n(g);
    58       NodeIt n(g);
    59       int j = 1;
    59       int j = 1;
    60       while (j < i) {
    60       while (j < i) {
    61         ++n;
    61         ++n;
    62         ++j;
    62         ++j;
    89     Entity* clone() { return new Entity(*this); }
    89     Entity* clone() { return new Entity(*this); }
    90     void randomize() {
    90     void randomize() {
    91       for (NodeIt n(g); n != INVALID; ++n)
    91       for (NodeIt n(g); n != INVALID; ++n)
    92         a[n] = false;
    92         a[n] = false;
    93       for (NodeIt n(g); n != INVALID; ++n)
    93       for (NodeIt n(g); n != INVALID; ++n)
    94         if (rand() < 0.5) a[n] = true;
    94         if (rnd.boolean(0.5)) a[n] = true;
    95       sum = 0;
    95       sum = 0;
    96       for (EdgeIt e(g); e != INVALID; ++e)
    96       for (EdgeIt e(g); e != INVALID; ++e)
    97         if (a[g.source(e)] != a[g.target(e)])
    97         if (a[g.source(e)] != a[g.target(e)])
    98           sum += w[e];
    98           sum += w[e];
    99     }
    99     }