Project

General

Profile

Statistics
| Branch: | Revision:

cool / src / lib / GMLMIP-0.1 / rules / valuation.c @ 7c4d2eb4

History | View | Annotate | Download (1.04 KB)

1 e034e268 Thorsten WiƟmann
#include "valuation.h"
2
3
Valuation::Valuation(int i, int no_of_vars){
4
        int limit = 1 << no_of_vars;
5
        if(i >= limit){
6
          cout << "cannot make clause " << i << " out of " << limit << endl;
7
}
8
        n = no_of_vars;
9
        
10
        p = new int [n];
11
        
12
        int ui = i;        
13
        
14
        for(int j=0; j < no_of_vars; j++){
15
                p[j] = ui & 1;
16
                ui >>=1;
17
        }
18
        
19
}
20
        
21
22
Valuation::Valuation(int _n, int* _p){
23
        n = _n;
24
        p = new int [n];
25
        
26
        for(int i=0; i < n; i++)
27
                p[i]=_p[i];
28
}        
29
30
Valuation::Valuation(const Valuation& c){
31
        n = c.n;
32
        p = new int [n];
33
        
34
        for(int i=0; i < n; i++)
35
                p[i]=c.p[i];
36
}
37
38
Valuation& Valuation::operator=(const Valuation& c){
39
        if(this != &c){
40
                if(p)
41
                        delete [] p;
42
                n = c.n;
43
                p = new int [n];
44
        
45
                for(int i=0; i < n; i++)
46
                        p[i]=c.p[i];
47
        }
48
        return *this;
49
}
50
51
52
Valuation::~Valuation(){
53
        if(p)
54
                delete [] p;
55
}
56
57
int Valuation::get_p_i(int i){
58
        if(p)
59
                return p[i];
60
        return -1;
61
}
62
63
bool Valuation::operator==(const Valuation& other) const{
64
                if(n == other.n){
65
                        for(int i = 0; i < n; i++)
66
                                if(p[i]!=other.p[i])
67
                                        return false;
68
                        return true;
69
                }
70
                return false;
71
                }