Check in a README file
[satcheck.git] / branchrecord.cc
1 /*      Copyright (c) 2015 Regents of the University of California
2  *
3  *      Author: Brian Demsky <bdemsky@uci.edu>
4  *
5  *      This program is free software; you can redistribute it and/or
6  *      modify it under the terms of the GNU General Public License
7  *      version 2 as published by the Free Software Foundation.
8  */
9
10 #include "branchrecord.h"
11 #include "mymemory.h"
12 #include "constraint.h"
13 #include "eprecord.h"
14
15 BranchRecord::BranchRecord(EPRecord *r, uint nvars, Constraint **cvars, bool isalwaysexecuted) :
16         branch(r),
17         hasNext(r->getNextRecord()!=NULL),
18         numvars(nvars),
19         numdirections(r->numValues()),
20         alwaysexecuted(isalwaysexecuted),
21         vars((Constraint **)model_malloc(sizeof(Constraint *)*nvars)) {
22         memcpy(vars, cvars, sizeof(Constraint *)*nvars);
23 }
24
25 BranchRecord::~BranchRecord() {
26         model_free(vars);
27 }
28
29 Constraint * BranchRecord::getAnyBranch() {
30         if (alwaysexecuted)
31                 return &ctrue;
32         else
33                 return new Constraint(OR, numvars, vars);
34 }
35
36 Constraint * BranchRecord::getNewBranch() {
37         return new Constraint(AND, numvars, vars);
38 }
39
40 Constraint * BranchRecord::getBranch(EPValue *val) {
41         int index=branch->getIndex(val);
42         ASSERT(index>=0);
43         if (!alwaysexecuted)
44                 index++;
45         return generateConstraint(numvars, vars, index);
46 }
47
48 int BranchRecord::getBranchValue(bool * array) {
49         uint value=0;
50         for(int j=numvars-1;j>=0;j--) {
51                 value=value<<1;
52                 if (array[vars[j]->getVar()])
53                         value|=1;
54         }
55         if (!alwaysexecuted)
56                 value--;
57
58         return value;
59 }