9 template<class Settings>
10 ICEModule<Settings>::ICEModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager):
11 PModule( _formula, _conditionals, _manager, Settings::moduleName )
14 template<class Settings>
15 ICEModule<Settings>::~ICEModule()
18 template<class Settings>
19 bool ICEModule<Settings>::addCore( ModuleInput::const_iterator _subformula )
21 addReceivedSubformulaToPassedFormula(_subformula);
22 addFormula(_subformula->formula());
26 template<class Settings>
27 void ICEModule<Settings>::removeCore( ModuleInput::const_iterator _subformula )
29 removeFormula(_subformula->formula());
32 template<class Settings>
33 Answer ICEModule<Settings>::checkCore()
35 SMTRAT_LOG_DEBUG("smtrat.ice", "Obtained the following bounds: " << std::endl << mBounds);
36 Answer res = processConstraints();
37 if (res == UNSAT) return UNSAT;
40 if (res == UNSAT) getInfeasibleSubsets();
44 template<class Settings>
45 void ICEModule<Settings>::addFormula(const FormulaT& f) {
47 case carl::FormulaType::CONSTRAINT:
48 mBounds.addBound(f.constraint(), f);
49 if (!carl::is_bound(f.constraint())) {
50 mConstraints.emplace(f, f.constraint());
53 case carl::FormulaType::NOT: {
54 if (f.subformula().type() == carl::FormulaType::CONSTRAINT) {
55 const ConstraintT& c = f.subformula().constraint();
56 ConstraintT newC(c.lhs(), inverse(c.relation()));
57 mBounds.addBound(newC, f);
58 if (!carl::is_bound(newC)) {
59 mConstraints.emplace(f, newC);
69 template<class Settings>
70 void ICEModule<Settings>::removeFormula(const FormulaT& f) {
72 case carl::FormulaType::CONSTRAINT:
73 mBounds.removeBound(f.constraint(), f);
74 if (!carl::is_bound(f.constraint())) {
75 mConstraints.erase(f);
78 case carl::FormulaType::NOT: {
79 if (f.subformula().type() == carl::FormulaType::CONSTRAINT) {
80 const ConstraintT& c = f.subformula().constraint();
81 ConstraintT newC(c.lhs(), inverse(c.relation()));
82 mBounds.removeBound(newC, f);
83 if (!carl::is_bound(newC)) {
84 mConstraints.erase(f);
94 template<class Settings>
95 Answer ICEModule<Settings>::processConstraints() {
96 if (mBounds.isConflicting()) {
97 mInfeasibleSubsets.emplace_back(mBounds.getConflict());
102 std::vector<TermT> dest;
104 for (const auto& c: mConstraints) {
105 if (isSuitable(c.second, src, dest, coeff)) {
106 auto& edge = graph.newEdge(graph.newVertex(src), EdgeProperty(coeff, c.first));
107 for (const auto& d: dest) {
108 edge.addOut(graph.newVertex(d));
112 if (Settings::dumpAsDot) {
113 SMTRAT_LOG_INFO("smtrat.ice", "Dumping resulting graph to " << Settings::dotFilename);
114 graph.toDot(Settings::dotFilename);
117 CycleCollector collector;
118 CycleEnumerator<FHG,CycleCollector> enumerator(graph, collector);
119 enumerator.findAll();
121 if (!collector.mInfeasibleSubset.empty()) {
122 SMTRAT_LOG_INFO("smtrat.ice", "Found input to be unsat, subset is " << collector.mInfeasibleSubset);
123 mInfeasibleSubsets.emplace_back(collector.mInfeasibleSubset);
126 for (const auto& lemma: collector.mLemmas) {
127 SMTRAT_LOG_DEBUG("smtrat.ice", "Adding " << lemma.first << " with origin " << lemma.second);
128 addSubformulaToPassedFormula(lemma.first, lemma.second);
133 template<class Settings>
134 bool ICEModule<Settings>::isSuitable(const ConstraintT& c, TermT& src, std::vector<TermT>& dest, Coefficient& coeff) {
135 SMTRAT_LOG_FUNC("smtrat.ice", c);
139 coeff.strict = false;
142 switch (c.relation()) {
143 case carl::Relation::EQ: break;
144 case carl::Relation::NEQ: return false;
145 case carl::Relation::LESS:
149 case carl::Relation::LEQ:
152 case carl::Relation::GREATER:
155 case carl::Relation::GEQ: break;
160 for (const auto& term: p) {
161 if (term.is_constant()) {
162 coeff.r += term.coeff();
166 SMTRAT_LOG_WARN("smtrat.ice", "Term " << term << " is zero. We'll ignore it.");
169 if (isSemiPositive(term)) {
170 if (!carl::is_zero(src)) {
171 SMTRAT_LOG_TRACE("smtrat.ice", "No: Already has a source, but " << term << " was found.");
175 } else if (isSemiNegative(term)) {
176 dest.push_back(-term);
178 SMTRAT_LOG_TRACE("smtrat.ice", "No: Has indefinite term " << term << ".");
183 SMTRAT_LOG_TRACE("smtrat.ice", "No: No destinations were found.");
186 SMTRAT_LOG_TRACE("smtrat.ice", "Yes: " << src << " -> " << dest << " with coefficient " << coeff << ".");