blob: 64407684b8861c816da8b132e52614bfdf83519b (
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
|
/********************* */
/*! \file idl_model.h
** \verbatim
** Original author: Dejan Jovanovic
** Major contributors: none
** Minor contributors (to current version): none
** This file is part of the CVC4 project.
** Copyright (c) 2009-2013 New York University and The University of Iowa
** See the file COPYING in the top-level source directory for licensing
** information.\endverbatim
**
** \brief [[ Add one-line brief description here ]]
**
** [[ Add lengthier description here ]]
** \todo document this file
**/
#pragma once
#include "expr/node.h"
#include "context/cdhashmap.h"
namespace CVC4 {
namespace theory {
namespace idl {
/**
* A reason for a value of a variable in the model is a constraint that implies
* this value by means of the value of another variable. For example, if the
* value of x is 0, then the variable x and the constraint (y > 0) are a reason
* for the y taking the value 1.
*/
struct IDLReason {
/** The variable of the reason */
TNode x;
/** The constraint of the reaason */
TNode constraint;
IDLReason(TNode x, TNode constraint)
: x(x), constraint(constraint) {}
IDLReason() {}
};
/**
* A model maps variables to integer values and backs them up with reasons.
* Default values (if not set with setValue) for all variables are 0.
*/
class IDLModel {
typedef context::CDHashMap<TNode, Integer, TNodeHashFunction> model_value_map;
typedef context::CDHashMap<TNode, IDLReason, TNodeHashFunction> model_reason_map;
/** Values assigned to individual variables */
model_value_map d_model;
/** Reasons constraining the individual variables */
model_reason_map d_reason;
public:
IDLModel(context::Context* context);
/** Get the model value of the variable */
Integer getValue(TNode var) const;
/** Set the value of the variable */
void setValue(TNode var, Integer value, IDLReason reason);
/** Get the cycle of reasons behind the variable var */
void getReasonCycle(TNode var, std::vector<TNode>& reasons);
/** Output to the given stream */
void toStream(std::ostream& out) const;
};
inline std::ostream& operator << (std::ostream& out, const IDLModel& model) {
model.toStream(out);
return out;
}
}
}
}
|