Project

General

Profile

Statistics
| Branch: | Revision:

cool / src / lib / GMLMIP-0.1 / formulas / GML_formula.c @ 7c4d2eb4

History | View | Annotate | Download (1.79 KB)

1
#include "GML_formula.h"
2

    
3
bdd GML_Formula::modal(bdd *b, int n, int m){
4
        return modal_var(b, n);
5
}
6
 
7
void GML_Formula::load_linear_program(glp_prob* problem, Premise<int>& prem){
8
        int n = prem.get_n();
9
        int m = prem.get_m();
10
        int no_of_valuations = prem.get_total_valuations();
11
        
12
        //glp_set_obj_dir(sc, GLP_MIN);
13
        glp_add_rows(problem, no_of_valuations+1);
14
        glp_add_cols(problem, n+m);
15
        
16
        for(int i = 1; i < no_of_valuations+1; i++)
17
                glp_set_row_bnds(problem, i, GLP_UP, 0.0, 0.0); // <= 0
18
                
19
        // Set row bounds for side condition
20
        glp_set_row_bnds(problem, no_of_valuations+1, GLP_LO, 1.0, 0.0); // >= 1
21
        
22
        for(int i=1; i < (n+m+1); i++){
23
                glp_set_col_kind(problem, i, GLP_IV); //integer variables
24
                glp_set_col_bnds(problem, i, GLP_LO, 0, 0); // r_i, s_i >= 0
25
        }
26
        
27
        // Arrays for inputting into glpk
28
        const int size = (no_of_valuations+1)*(n+m);
29
        double ar[size+1];
30
        int ia[size+1];
31
        int ja[size+1];
32
        
33
        // Recall GLKP takes arrays with 1 - size not 0 - size-1.
34
        for(int i=0; i < size; i++){
35
                   ia[i+1] = (i / (n+m)) + 1;
36
                   ja[i+1] = (i % (n+m)) + 1;        
37
           }
38
    
39
         int counter=1;
40
        
41
        // Load all valuations
42
        for(int i=0; i < no_of_valuations; i++){
43
                int temp = i;
44
                for(int j=0; j < n; j++){
45
                        ar[counter] = temp & 1;
46
                        temp >>= 1;
47
                        counter++;
48
                }
49
                for(int j=0; j < m; j++){
50
                        ar[counter] = -(temp & 1);
51
                        temp >>= 1;
52
                        counter++;
53
                }
54
        }
55
        
56
        // Load side condition at the bottom
57
        for(int i=0; i < n; i++){
58
                ar[counter]= prem.get_a_i(i)+1;
59
                counter++;
60
        }
61
        
62
        for(int j=0; j < m; j++){
63
                ar[counter]= -(prem.get_b_i(j));
64
                counter++;
65
        }
66
        
67
        /*
68
        for(int i=1; i < size+1; i++)
69
                cout << ia[i] << " ";
70
        cout << endl;
71
        for(int i=1; i < size+1; i++)
72
                cout << ja[i] << " ";
73
        cout << endl << endl;        
74
        for(int i=1; i < size+1; i++)
75
                cout << ar[i] << " ";
76
        cout << endl;
77
        */
78
        
79
        glp_load_matrix(problem, size, ia, ja, ar);
80
}