### Profile

Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.53 KB)

1 2 3 e034e268 Thorsten Wißmann ```#include "PML_formula.h" ``` ```bdd PML_Formula::modal(bdd *b, int n, int m){ ``` ``` if(n > m){ ``` ``` cout << "error: " << n << "/" << m << " is not in [0,1]" << endl; ``` ``` exit(1); ``` ``` } ``` ``` Rational r(n,m); ``` ``` return modal_var(b, r); ``` ```} ``` ```void PML_Formula::load_linear_program(glp_prob* problem, Premise& prem) { ``` ``` int n = prem.get_n(); ``` ``` int m = prem.get_m(); ``` ``` int no_of_valuations = prem.get_total_valuations(); ``` ``` ``` ``` // Additional 2 for side condition and requirements that at least one r_i,s_j is non zero ``` ``` glp_add_rows(problem, no_of_valuations+2); ``` ``` // Additional column for k ``` ``` glp_add_cols(problem, n+m+1); ``` ``` ``` ``` for(int i = 1; i < no_of_valuations+1; i++) ``` ``` glp_set_row_bnds(problem, i, GLP_UP, 0.0, 0.0); // <= 0 ``` ``` ``` ``` // Set row bounds for side condition - recall we have -k in the extra column. ``` ``` if(m==0) ``` ``` glp_set_row_bnds(problem, no_of_valuations+1, GLP_LO, 1.0, 0.0); // >= 1 ``` ``` else ``` ``` glp_set_row_bnds(problem, no_of_valuations+1, GLP_LO, 0.0, 0.0); // >= 0 ``` ``` ``` ``` // Set row bounds for additional constraint ``` ``` glp_set_row_bnds(problem, no_of_valuations+2, GLP_LO, 1.0, 0.0); // >= 1 ``` ``` ``` ``` // Set variable bounds ``` ``` for(int i=1; i < (n+m+1); i++){ ``` ``` glp_set_col_kind(problem, i, GLP_IV); //integer variables ``` ``` glp_set_col_bnds(problem, i, GLP_LO, 0, 0); // r_i, s_i >= 0 ``` ``` } ``` ``` ``` ``` // K is positive integer ``` ``` glp_set_col_kind(problem, n+m+1, GLP_IV); //integer k ``` ``` glp_set_col_bnds(problem, n+m+1, GLP_LO, 1.0, 0.0); // k >= 1 ``` ``` ``` ``` ``` ``` // Arrays for inputting into glpk ``` ``` const int size = (no_of_valuations+2)*(n+m+1); ``` ``` double ar[size+1]; ``` ``` int ia[size+1]; ``` ``` int ja[size+1]; ``` ``` ``` ``` // Recall GLKP takes arrays with 1 - size not 0 - size-1. ``` ``` for(int i=0; i < size; i++){ ``` ``` ia[i+1] = (i / (n+m+1)) + 1; ``` ``` ja[i+1] = (i % (n+m+1)) + 1; ``` ``` } ``` ``` ``` ``` int counter=1; ``` ``` ``` ``` // Load all valuations ``` ``` for(int i=0; i < no_of_valuations; i++){ ``` ``` int temp = i; ``` ``` for(int j=0; j < n; j++){ ``` ``` ar[counter] = temp & 1; ``` ``` temp >>= 1; ``` ``` counter++; ``` ``` } ``` ``` for(int j=0; j < m; j++){ ``` ``` ar[counter] = -(temp & 1); ``` ``` temp >>= 1; ``` ``` counter++; ``` ``` } ``` ``` ar[counter] = -1; // - k on each valuation. ``` ``` counter++; ``` ``` } ``` ``` ``` ``` // Load side condition ``` ``` for(int i=0; i < n; i++){ ``` ``` ar[counter] = prem.get_a_i(i).get(); ``` ``` counter++; ``` ``` } ``` ``` ``` ``` for(int j=0; j < m; j++){ ``` ``` ar[counter]= -(prem.get_b_i(j).get()); ``` ``` counter++; ``` ``` } ``` ``` //side condition has coefficent k of -1 ``` ``` ar[counter] = -1; ``` ``` counter++; ``` ``` ``` ``` //Finally load condition that one must be nonzero. ``` ``` for(int i=0; i < n+m; i++){ ``` ``` ar[counter] = 1; ``` ``` counter++; ``` ``` } ``` ``` // k coefficient here is zero ``` ``` ar[counter] = 0; ``` ``` ``` ``` glp_load_matrix(problem, size, ia, ja, ar); ``` ``` //glp_write_lp(problem, NULL, "testy.txt"); ``` `}`