File: Mongoose_Test_EdgeSeparator.cpp

package info (click to toggle)
suitesparse 1%3A5.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 138,928 kB
  • sloc: ansic: 389,614; cpp: 24,213; makefile: 5,965; fortran: 1,927; java: 1,808; csh: 1,750; ruby: 725; sh: 226; perl: 225; python: 209; sed: 164; awk: 60
file content (86 lines) | stat: -rw-r--r-- 2,171 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <string>
#include "Mongoose_IO.hpp"
#include "Mongoose_EdgeCut.hpp"
#include "Mongoose_Test.hpp"
#include <fstream>

using namespace Mongoose;

int runEdgeSeparatorTest(const std::string &inputFile, const double targetSplit)
{
    LogTest("Running Edge Separator Test on " << inputFile);
        
    // Given a symmetric matrix...
    EdgeCut_Options *options;
    Graph *graph;
    
    options = EdgeCut_Options::create();
    if (!options)
    {
        // Ran out of memory
        LogTest("Error creating Options struct in Edge Separator Test");
        return EXIT_FAILURE;
    }

    options->target_split = targetSplit;
    
    // Read graph from file
    graph = read_graph(inputFile);

    if (!graph)
    {
        // Ran out of memory
        LogTest("Error reading Graph from file in Edge Separator Test");
        options->~EdgeCut_Options();
        return EXIT_FAILURE;
    }

    // An edge separator should be computed with default options
    EdgeCut *result = edge_cut(graph, options);

    options->~EdgeCut_Options();

    if (!result)
    {
        // Error occurred
        LogTest("Error computing edge cut in Edge Separator Test");
        return EXIT_FAILURE;
    }
    else
    {
        // The graph should be partitioned
        assert (result->partition != NULL);
        int count = 0;
        for (int i = 0; i < result->n; i++)
        {
            bool equals_0 = (result->partition[i] == 0);
            bool equals_1 = (result->partition[i] == 1);
            assert(equals_0 != equals_1);

            count += result->partition[i];
        }

        double split = (double) count / (double) graph->n;
        double target = targetSplit;
        if (split > 0.5)
        {
            split = 1 - split;
        }
        if (targetSplit > 0.5)
        {
            target = 1 - target;
        }

        Logger::printTimingInfo();
        LogTest("Cut Properties:");
        LogTest("  Cut Cost:  " << result->cut_cost);
        LogTest("  Imbalance: " << result->imbalance);
    }

    graph->~Graph();
    result->~EdgeCut();

    LogTest("Edge Separator Test Completed Successfully");

    return EXIT_SUCCESS;
}