summaryrefslogtreecommitdiff
path: root/cryptominisat5/cryptominisat-5.6.3/src/packedrow.cpp
blob: 6e0d9002ebf1a05b78d37eeaa2c455454f115d34 (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/******************************************
Copyright (c) 2018  Mate Soos
Copyright (c) 2012  Cheng-Shen Han
Copyright (c) 2012  Jie-Hong Roland Jiang

For more information, see " When Boolean Satisfiability Meets Gaussian
Elimination in a Simplex Way." by Cheng-Shen Han and Jie-Hong Roland Jiang
in CAV (Computer Aided Verification), 2012: 410-426


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
***********************************************/

#include "packedrow.h"

using namespace CMSat;

bool PackedRow::fill(
    vec<Lit>& tmp_clause,
    const vec<lbool>& assigns,
    const vector<uint32_t>& col_to_var_original
) const
{
    bool final = !rhs_internal;

    tmp_clause.clear();
    uint32_t col = 0;
    bool wasundef = false;
    for (uint32_t i = 0; i < size; i++) for (uint32_t i2 = 0; i2 < 64; i2++) {
        if ((mp[i] >> i2) &1) {
            const uint32_t& var = col_to_var_original[col];
            assert(var != std::numeric_limits<uint32_t>::max());

            const lbool val = assigns[var];
            const bool val_bool = val == l_True;
            tmp_clause.push(Lit(var, val_bool));
            final ^= val_bool;
            if (val == l_Undef) {
                assert(!wasundef);
                Lit tmp(tmp_clause[0]);
                tmp_clause[0] = tmp_clause.last();
                tmp_clause.last() = tmp;
                wasundef = true;
            }
        }
        col++;
    }
    if (wasundef) {
        tmp_clause[0] ^= final;
        //assert(ps != ps_first+1);
    } else
        assert(!final);

    return wasundef;
}

///returns popcnt
uint32_t PackedRow::find_watchVar(
    vector<Lit>& tmp_clause,
    const vector<uint32_t>& col_to_var,
    vec<bool> &GasVar_state,
    uint32_t& nb_var
) {
    uint32_t  tmp_var = 0;
    uint32_t popcnt = 0;
    nb_var = std::numeric_limits<uint32_t>::max();
    uint32_t i;
    tmp_clause.clear();


    for(i = 0; i < size*64; i++) {
        if (this->operator[](i)){
            popcnt++;
            tmp_var = col_to_var[i];
            tmp_clause.push_back(Lit(tmp_var, false));
            if( !GasVar_state[tmp_var] ){  //nobasic
                nb_var = tmp_var;
                break;
            }else{  // basic
                Lit tmp(tmp_clause[0]);
                tmp_clause[0] = tmp_clause.back();
                tmp_clause.back() = tmp;
            }
        }
    }

    for( i = i + 1 ; i <  size*64; i++) {
        if (this->operator[](i)){
            popcnt++;
            tmp_var = col_to_var[i];
            tmp_clause.push_back(Lit(tmp_var, false));
            if( GasVar_state[tmp_var] ){  //basic
                Lit tmp(tmp_clause[0]);
                tmp_clause[0] = tmp_clause.back();
                tmp_clause.back() = tmp;
            }
        }
    }
    assert(tmp_clause.size() == popcnt);
    assert( popcnt == 0 || GasVar_state[ tmp_clause[0].var() ]) ;
    return popcnt;

}

gret PackedRow::propGause(
    vector<Lit>& tmp_clause,
    const vector<lbool>& assigns,
    const vector<uint32_t>& col_to_var,
    vec<bool> &GasVar_state, // variable state  : basic or non-basic
    uint32_t& nb_var,
    uint32_t start
) {

    bool final = !rhs_internal;
    nb_var = std::numeric_limits<uint32_t>::max();
    tmp_clause.clear();

    for (uint32_t i = start/64; i != size; i++) if (mp[i]) {
        uint64_t tmp = mp[i];
        for (uint32_t i2 = 0 ; i2 < 64; i2++) {
            if(tmp & 1){
                const uint32_t var = col_to_var[i * 64  + i2];
                const lbool val = assigns[var];
                if (val == l_Undef && !GasVar_state[var]) {  // find non basic value
                    nb_var = var;
                    return gret::nothing_fnewwatch;   // nothing
                }
                const bool val_bool = (val == l_True);
                final ^= val_bool;
                tmp_clause.push_back(Lit(var, val_bool));
                if (likely(GasVar_state[var])) {
                    std::swap(tmp_clause[0], tmp_clause.back());
                }
            }
            tmp >>= 1;
        }
    }

    for ( uint32_t i =0; i != start/64; i++) if (likely(mp[i])) {
        uint64_t tmp = mp[i];
        for (uint32_t i2 = 0 ; i2 < 64; i2++) {
            if(tmp & 1){
                const uint32_t var = col_to_var[i * 64  + i2];
                const lbool val = assigns[var];
                if (val == l_Undef &&  !GasVar_state[var] ){  // find non basic value
                    nb_var = var;
                    return gret::nothing_fnewwatch;   // nothing
                }
                const bool val_bool = val == l_True;
                final ^= val_bool;
                tmp_clause.push_back(Lit(var, val_bool));
                if ( GasVar_state[var] ) {
                    std::swap(tmp_clause[0], tmp_clause.back());
                }
            }
            tmp >>= 1;
        }
    }

    if (assigns[tmp_clause[0].var()] == l_Undef) {    // propogate
        tmp_clause[0] = tmp_clause[0].unsign()^final;
        return gret::prop;  // propogate
    } else if (!final) {
        return gret::confl;  // conflict
    }
    // this row already true
    return gret::nothing;  // nothing

}




generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback