// ==================================================== // Integral constraint // ==================================================== integral_constraint mk_integral_constraint(Enode * const e, unordered_map<string, flow> const & flow_map) { // nra_solver::inform: (integral 2 0 time_9 v_9_0 v_9_t x_9_0 x_9_t) Enode const * tmp = e->getCdr(); unsigned flow_id = tmp->getCar()->getValue(); tmp = tmp->getCdr(); Enode * const time_0 = tmp->getCar(); tmp = tmp->getCdr(); Enode * const time_t = tmp->getCar(); tmp = tmp->getCdr(); string key = string("flow_") + to_string(flow_id); auto const it = flow_map.find(key); if (it == flow_map.end()) { throw std::logic_error(key + " is not in flow_map. Failed to create integral constraint"); } flow const & _flow = it->second; vector<string> const & flow_vars = _flow.get_vars(); vector<Enode *> const & flow_odes = _flow.get_odes(); vector<Enode *> vars_0, vars_t, pars_0, pars_t; vector<string> par_lhs_names; vector<pair<string, Enode *>> odes; for (unsigned i = 0; i < flow_vars.size(); i++) { Enode * const var_0 = tmp->getCar(); tmp = tmp->getCdr(); Enode * const var_t = tmp->getCar(); tmp = tmp->getCdr(); string const & ode_var = flow_vars[i]; Enode * const ode_rhs = flow_odes[i]; if (ode_rhs->isConstant() && ode_rhs->getValue() == 0.0) { // Parameter pars_0.push_back(var_0); pars_t.push_back(var_t); par_lhs_names.push_back(ode_var); } else { // Variable vars_0.push_back(var_0); vars_t.push_back(var_t); odes.emplace_back(ode_var, ode_rhs); } } assert(tmp->isEnil()); return integral_constraint(e, flow_id, time_0, time_t, vars_0, pars_0, vars_t, pars_t, par_lhs_names, odes); }
// ==================================================== // Integral constraint // ==================================================== integral_constraint mk_integral_constraint(Enode * const e, unordered_map<string, flow> const & flow_map) { // nra_solver::inform: (integral 2 0 time_9 v_9_0 v_9_t x_9_0 x_9_t) Enode const * tmp = e->getCdr(); unsigned flow_id = tmp->getCar()->getValue(); tmp = tmp->getCdr(); Enode * const time_0 = tmp->getCar(); tmp = tmp->getCdr(); Enode * const time_t = tmp->getCar(); tmp = tmp->getCdr(); string key = string("flow_") + to_string(flow_id); auto const it = flow_map.find(key); if (it == flow_map.end()) { throw logic_error(key + " is not in flow_map. Failed to create integral constraint"); } flow const & _flow = it->second; vector<Enode *> const & flow_vars = _flow.get_vars(); vector<Enode *> const & flow_odes = _flow.get_odes(); vector<Enode *> vars_0, vars_t, pars_0, pars_t; vector<Enode *> par_lhs_names; vector<pair<Enode *, Enode *>> odes; for (unsigned i = 0; i < flow_vars.size(); i++) { Enode * const var_0 = tmp->getCar(); tmp = tmp->getCdr(); Enode * const var_t = tmp->getCar(); tmp = tmp->getCdr(); Enode * const ode_var = flow_vars[i]; Enode * const ode_rhs = flow_odes[i]; if (ode_rhs->isConstant() && ode_rhs->getValue() == 0.0) { // Parameter pars_0.push_back(var_0); pars_t.push_back(var_t); par_lhs_names.push_back(ode_var); } else { // Variable vars_0.push_back(var_0); vars_t.push_back(var_t); odes.emplace_back(ode_var, ode_rhs); } } if (!tmp->isEnil()) { DREAL_LOG_FATAL << "We found a problem in handling: " << e; DREAL_LOG_FATAL << "You provided " << flow_vars.size() << " differential equation(s) in the system:"; for (unsigned i = 0; i < flow_vars.size(); i++) { DREAL_LOG_FATAL << "\t" << "d/dt[" << flow_vars[i] << "] = " << flow_odes[i]; } DREAL_LOG_FATAL << "However, there are " << (flow_vars.size() + tmp->getSize()) << " pairs of variables shown:"; tmp = e->getCdr()->getCdr()->getCdr()->getCdr(); while (!tmp->isEnil()) { DREAL_LOG_FATAL << "\t" << tmp->getCar() << ", " << tmp->getCdr()->getCar(); tmp = tmp->getCdr()->getCdr(); } abort(); } return integral_constraint(e, flow_id, time_0, time_t, vars_0, pars_0, vars_t, pars_t, par_lhs_names, odes); }