summaryrefslogtreecommitdiff
path: root/src/theory/idl/idl_assertion.h
blob: 9a31f283dbf3f50db01141f201a13ee093fb54eb (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
/*********************                                                        */
/*! \file idl_assertion.h
 ** \verbatim
 ** Original author: Dejan Jovanovic
 ** Major contributors: Morgan Deters
 ** Minor contributors (to current version): none
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2014  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 "theory/idl/idl_model.h"

namespace CVC4 {
namespace theory {
namespace idl {

/**
 * An internal representation of the IDL assertions. Each IDL assertions is
 * of the form (x - y op c) where op is one of (<=, =, !=). IDL assertion
 * can be constructed from an expression.
 */
class IDLAssertion {

  /** The positive variable */
  TNode d_x;
  /** The negative variable */
  TNode d_y;
  /** The relation */
  Kind d_op;
  /** The RHS constant */
  Integer d_c;

  /** Original assertion we got this one from */
  TNode d_original;

  /** Parses the given node into an assertion, and return true if OK. */
  bool parse(TNode node, int c = 1, bool negated = false);

public:

  /** Null assertion */
  IDLAssertion();
  /** Create the assertion from given node */
  IDLAssertion(TNode node);
  /** Copy constructor */
  IDLAssertion(const IDLAssertion& other);

  TNode getX() const { return d_x; }
  TNode getY() const { return d_y; }
  Kind getOp() const { return d_op;}
  Integer getC() const { return d_c; }

  /**
   * Propagate the constraint using the model. For example, if the constraint
   * is of the form x - y <= -1, and the value of x in the model is 0, then
   *
   *   (x - y <= -1) and (x = 0) implies y >= x + 1 = 1
   *
   * If the value of y is less then 1, is is set to 1 and true is returned. If
   * the value of y is 1 or more, than false is return.
   *
   * @return true if value of y was updated
   */
  bool propagate(IDLModel& model) const;

  /** Is this constraint proper */
  bool ok() const {
    return !d_x.isNull() || !d_y.isNull();
  }

  /** Output to the stream */
  void toStream(std::ostream& out) const;
};

inline std::ostream& operator << (std::ostream& out, const IDLAssertion& assertion) {
  assertion.toStream(out);
  return out;
}

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