Statistics
| Branch: | Tag: | Revision:

sssimulator / Test / overlay_test.c @ f1158e5c

History | View | Annotate | Download (2.28 KB)

1
/*
2
 * This is SSSim: the Simple & Stupid Simulator
3
 *
4
 *  Copyright (c) 2015 Luca Baldesi
5
 *
6
 *  This is free software; see gpl-3.0.txt
7
 */
8

    
9
#include <assert.h>
10
#include <stdio.h>
11
#include <math.h>
12

    
13
#include <matrix.h>
14

    
15
int PO_DELAY;    // playout delay
16
float convergence_precision = 0;
17
float netload = 1;
18

    
19
void write_edgefile()
20
{
21
        FILE *efile;
22

    
23
        efile = fopen("net.edges", "w");
24
        fputs("0 1 1\n", efile);
25
        fputs("1 2 1\n", efile);
26
        fputs("2 3 1\n", efile);
27
        fputs("4 0 1\n", efile);
28
        fputs("5 0 1\n", efile);
29
        fputs("0 4 1\n", efile);
30
        fputs("0 5 1\n", efile);
31
        fputs("1 0 1\n", efile);
32
        fputs("2 1 1\n", efile);
33
        fputs("2 5 1\n", efile);
34
        fputs("3 2 1\n", efile);
35
        fputs("3 5 1\n", efile);
36
        fputs("4 5 1\n", efile);
37
        fputs("5 2 1\n", efile);
38
        fputs("5 3 1\n", efile);
39
        fputs("5 4 1\n", efile);
40
        fclose(efile);
41
}
42

    
43
void overlay_matrix_optimize_test()
44
{
45
        struct matrix * A, * x, *res;
46

    
47
        write_edgefile();
48
        A = matrix_from_edgefile("net.edges");
49
        matrix_stochastify(A);
50
        x = matrix_eigencentrality(A, NULL);
51

    
52
        // octave: optimized A
53
        //    0.00000   0.50000   0.00000   0.00000   0.56305   0.20439
54
        //    0.39101   0.00000   0.39101   0.00000   0.00000   0.00000
55
        //    0.00000   0.50000   0.00000   0.56305   0.00000   0.20439
56
        //    0.00000   0.00000   0.39633   0.00000   0.00000   0.29561
57
        //    0.39633   0.00000   0.00000   0.00000   0.00000   0.29561
58
        //    0.21266   0.00000   0.21266   0.43695   0.43695   0.00000
59
        // octave: optimized x
60
        //    1.21641   0.70082   1.21641   0.61400   0.61400   1.57614
61

    
62
        overlay_matrix_optimize(&A, &x);
63
        res = matrix_multiply(A, x);
64
        assert(matrix_element_get(res, 0, 0) < 1.1);
65
        assert(matrix_element_get(res, 0, 0) > 0.9);
66
        assert(matrix_element_get(res, 1, 0) < 1.1);
67
        assert(matrix_element_get(res, 1, 0) > 0.9);
68
        assert(matrix_element_get(res, 2, 0) < 1.1);
69
        assert(matrix_element_get(res, 2, 0) > 0.9);
70
        assert(matrix_element_get(res, 3, 0) < 1.1);
71
        assert(matrix_element_get(res, 3, 0) > 0.9);
72
        assert(matrix_element_get(res, 4, 0) < 1.1);
73
        assert(matrix_element_get(res, 4, 0) > 0.9);
74
        assert(matrix_element_get(res, 5, 0) < 1.1);
75
        assert(matrix_element_get(res, 5, 0) > 0.9);
76

    
77
        matrix_destroy(&A);
78
        matrix_destroy(&x);
79
        matrix_destroy(&res);
80
        fprintf(stderr,"%s successfully passed!\n",__func__);
81
}
82

    
83
int main(char ** argc,int argv)
84
{
85
        overlay_matrix_optimize_test();
86
        return 0;
87
}