File: Mongoose_Test_Reference.cpp

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (114 lines) | stat: -rw-r--r-- 3,383 bytes parent folder | download | duplicates (2)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//------------------------------------------------------------------------------
// Mongoose/Tests/Mongoose_Test_Reference.cpp
//------------------------------------------------------------------------------

// Mongoose Graph Partitioning Library, Copyright (C) 2017-2018,
// Scott P. Kolodziej, Nuri S. Yeralan, Timothy A. Davis, William W. Hager
// Mongoose is licensed under Version 3 of the GNU General Public License.
// Mongoose is also available under other licenses; contact authors for details.
// SPDX-License-Identifier: GPL-3.0-only

//------------------------------------------------------------------------------

#include <string>
#include "Mongoose_IO.hpp"
#include "Mongoose_EdgeCut.hpp"
#include "Mongoose_Test.hpp"
#include <fstream>

using namespace Mongoose;

int runReferenceTest(const std::string &inputFile)
{
    // Given a symmetric matrix
    EdgeCut_Options *options;
    Graph *graph;
    double t;
    
    options = EdgeCut_Options::create();

    if (!options)
    {
        // Ran out of memory
        LogTest("Error creating Options struct in Performance Test");
        return (EXIT_FAILURE);
    }

    graph = read_graph(inputFile);

    if (!graph)
    {
        // Ran out of memory
        return (EXIT_FAILURE);
    }

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

    if (!result)
    {
        // Error occurred
    }
    else
    {
        std::ofstream ofs ((inputFile + "_result.txt").c_str(), std::ofstream::out);
        ofs << "InputFile: " << inputFile << std::endl;
        ofs << "TotalTime: " << (t) << std::endl;
        ofs << "CutSize: " << result->cut_cost << std::endl;
        ofs << "Imbalance: " << result->imbalance << std::endl;

        for (int i = 0; i < graph->n; i++)
        {
            ofs << i << " ";
            if (result->partition[i] == 0)
            {
                ofs << "A" << std::endl;
            }
            else
            {
                ofs << "B" << std::endl;
            }
        }
        ofs.close();

        
        std::ifstream ifs (("../Tests/Results/" + inputFile + "_result.txt").c_str());
        std::string input;

        // Read file name
        ifs.ignore(200, ' ');
        ifs >> input;
        std::cout << "File Name: " << input << std::endl;

        // Read Total Time
        ifs.ignore(200, ' ');
        ifs >> input;
        double ref_time = strtod(input.c_str(), NULL);
        double test_time = t ;
        std::cout << "Test Time:      " << test_time << std::endl;
        std::cout << "Reference Time: " <<  ref_time << std::endl;
        

        // Read Cut Size
        ifs.ignore(200, ' ');
        ifs >> input;
        double ref_cut_size = strtod(input.c_str(), NULL);
        std::cout << "Test Cut Size: "      << result->cut_cost    << std::endl;
        std::cout << "Reference Cut Size: " <<  ref_cut_size << std::endl;

        ifs.close();

        assert(test_time <= 2*ref_time && 
            "FAIL: Run time significantly exceeds reference run time");
        assert(fabs(result->cut_cost) <= 1.1*fabs(ref_cut_size) &&
            "FAIL: Cut cost significantly exceeds reference cut size");
    }

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

    return EXIT_SUCCESS;
}