📄 mld_representation.cc
字号:
/** note that no checks are done here * e.g. it is possible to overwrite coefficients */void MLD_representation::set_coeff_eq(const Var_symbol * lhs, const Var_symbol * var, Expr * coeff) { Matrix * upd; // the Matrix in which coeff belongs if (var == NULL) { if (lhs->get_kind() == STATE_KIND) { if (lhs->get_type() == REAL_TYPE) upd = B5_r; else upd = B5_b; } else { if (lhs->get_type() == REAL_TYPE) upd = D5_r; else upd = D5_b; } upd->set(lhs->get_count(), 0, coeff); } else { upd = find_eq_mat(lhs->get_kind(), lhs->get_type(), var->get_kind(), var->get_type()); upd->set(lhs->get_count(), var->get_count(), coeff); }}void MLD_representation::set_info_eq(const Var_symbol * lhs, Row_information * info) { int ind; ind = lhs->get_count(); switch (lhs->get_kind()) { case STATE_KIND: if (lhs->get_type()==REAL_TYPE) state_upd_info[ind] = info; else state_upd_info[globals->symbol_table->count_symbols(STATE_KIND, REAL_TYPE) + ind] = info; break; case OUTPUT_KIND: if (lhs->get_type()==REAL_TYPE) output_info[ind] = info; else output_info[globals->symbol_table->count_symbols(OUTPUT_KIND, REAL_TYPE) + ind] = info; break; default: assert(0); //fine } info->set_mld(this, lhs);}void MLD_representation::set_coeff_ineq(int ineq, const Var_symbol * var, Expr * coeff) { Matrix * upd; // the Matrix in which coeff belongs if (var == NULL) { upd = E5; upd->set(ineq, 0, coeff); } else { upd = find_ineq_mat(var->get_kind(), var->get_type()); upd->set(ineq, var->get_count(), coeff); }}Expr * MLD_representation::get_coeff_ineq(int ineq, const Var_symbol * var) { Matrix * upd; if (var == NULL) { upd = E5; return upd->get(ineq, 0); } else { upd = find_ineq_mat(var->get_kind(), var->get_type()); return upd->get(ineq, var->get_count()); }}void MLD_representation::set_coeff_ineq_less(int ineq, const Var_symbol * var, Expr * coeff) { if (var == NULL || var->get_kind() == STATE_KIND || var->get_kind() == INPUT_KIND) set_coeff_ineq(ineq, var, new Neg_expr(coeff)); else set_coeff_ineq(ineq, var, coeff);}void MLD_representation::add_coeff_ineq_less(int ineq, const Var_symbol * var, Expr * coeff) { Expr * old_coeff, * new_coeff; old_coeff = get_coeff_ineq(ineq, var); if (old_coeff) { if (var == NULL || var->get_kind() == STATE_KIND || var->get_kind() == INPUT_KIND) new_coeff = new Minus_expr(old_coeff, coeff); else new_coeff = new Plus_expr(old_coeff, coeff); set_coeff_ineq(ineq, var, new_coeff); } else { set_coeff_ineq_less(ineq, var, coeff); }}void MLD_representation::set_info_ineq(int ineq, Row_information * info) { ineq_info[ineq] = info; info->set_mld(this, ineq);}Matrix * MLD_representation::find_eq_mat(Symb_kind lhs_kind, Symb_type lhs_type, Symb_kind var_kind, Symb_type var_type) const{ //cout << "lhstype " << lhs_type << " vartype " << var_type << endl; if (lhs_kind == STATE_KIND) { if (lhs_type == REAL_TYPE) { if (var_kind == STATE_KIND) { if (var_type == REAL_TYPE) return A_rr; if (var_type == BOOL_TYPE) return A_rb; } if (var_kind == INPUT_KIND) { if (var_type == REAL_TYPE) return B1_rr; if (var_type == BOOL_TYPE) return B1_rb; } if (var_kind == AUX_KIND) { if (var_type == REAL_TYPE) return B3_rr; if (var_type == BOOL_TYPE) return B2_rb; } } if (lhs_type == BOOL_TYPE) { if (var_kind == STATE_KIND) { if (var_type == REAL_TYPE) return A_br; if (var_type == BOOL_TYPE) return A_bb; } if (var_kind == INPUT_KIND) { if (var_type == REAL_TYPE) return B1_br; if (var_type == BOOL_TYPE) return B1_bb; } if (var_kind == AUX_KIND) { if (var_type == REAL_TYPE) return B3_br; if (var_type == BOOL_TYPE) return B2_bb; } } } if (lhs_kind == OUTPUT_KIND) { if (lhs_type == REAL_TYPE) { if (var_kind == STATE_KIND) { if (var_type == REAL_TYPE) return C_rr; if (var_type == BOOL_TYPE) return C_rb; } if (var_kind == INPUT_KIND) { if (var_type == REAL_TYPE) return D1_rr; if (var_type == BOOL_TYPE) return D1_rb; } if (var_kind == AUX_KIND) { if (var_type == REAL_TYPE) return D3_rr; if (var_type == BOOL_TYPE) return D2_rb; } } if (lhs_type == BOOL_TYPE) { if (var_kind == STATE_KIND) { if (var_type == REAL_TYPE) return C_br; if (var_type == BOOL_TYPE) return C_bb; } if (var_kind == INPUT_KIND) { if (var_type == REAL_TYPE) return D1_br; if (var_type == BOOL_TYPE) return D1_bb; } if (var_kind == AUX_KIND) { if (var_type == REAL_TYPE) return D3_br; if (var_type == BOOL_TYPE) return D2_bb; } } } assert(0); //fine return 0;}Matrix * MLD_representation::find_ineq_mat(Symb_kind kind, Symb_type type) const { switch (kind) { case STATE_KIND: if (type == REAL_TYPE) return E4_c; if (type == BOOL_TYPE) return E4_d; break; case INPUT_KIND: if (type == REAL_TYPE) return E1_c; if (type == BOOL_TYPE) return E1_d; break; case AUX_KIND: if (type == REAL_TYPE) return E3; if (type == BOOL_TYPE) return E2; break; default: assert(0); //fine } assert(0); //fine return 0;}void MLD_representation::merge(MLD_representation * from) { info_iter iter; //cout << "MLD_representation::merge START"; cout.flush(); * A_rr += from->A_rr->clone(); * A_br += from->A_br->clone(); * A_rb += from->A_rb->clone(); * A_bb += from->A_bb->clone(); * B1_rr += from->B1_rr->clone(); * B1_br += from->B1_br->clone(); * B1_rb += from->B1_rb->clone(); * B1_bb += from->B1_bb->clone(); * B3_rr += from->B3_rr->clone(); * B3_br += from->B3_br->clone(); * B2_rb += from->B2_rb->clone(); * B2_bb += from->B2_bb->clone(); * B5_r += from->B5_r->clone(); * B5_b += from->B5_b->clone(); * C_rr += from->C_rr->clone(); * C_br += from->C_br->clone(); * C_rb += from->C_rb->clone(); * C_bb += from->C_bb->clone(); * D1_rr += from->D1_rr->clone(); * D1_br += from->D1_br->clone(); * D1_rb += from->D1_rb->clone(); * D1_bb += from->D1_bb->clone(); * D3_rr += from->D3_rr->clone(); * D3_br += from->D3_br->clone(); * D2_rb += from->D2_rb->clone(); * D2_bb += from->D2_bb->clone(); * D5_r += from->D5_r->clone(); * D5_b += from->D5_b->clone(); check_ineqs(); from->check_ineqs(); E1_c->concat_y(from->E1_c->clone()); E1_d->concat_y(from->E1_d->clone()); E3->concat_y(from->E3->clone()); E2->concat_y(from->E2->clone()); E4_c->concat_y(from->E4_c->clone()); E4_d->concat_y(from->E4_d->clone()); E5->concat_y(from->E5->clone()); for (iter = from->state_upd_info.begin(); iter != from->state_upd_info.end(); iter++) { state_upd_info[(* iter).first] = (* iter).second; state_upd_info[(* iter).first] -> set_mld(this); } from->state_upd_info.clear(); for (iter = from->output_info.begin(); iter != from->output_info.end(); iter++) { output_info[(* iter).first] = (* iter).second; output_info[(* iter).first]->set_mld(this); } from->output_info.clear(); for (iter = from->ineq_info.begin(); iter != from->ineq_info.end(); iter++) { ineq_info[(* iter).first + nof_ineq] = (* iter).second; ineq_info[(* iter).first + nof_ineq]->set_mld(this, (* iter).first + nof_ineq); } from->ineq_info.clear(); nof_ineq += from->nof_ineq; delete from; //cout << "merge END"; cout.flush(); }string MLD_representation::row_to_string(const Var_symbol *lhs) const{ string res; list<const Var_symbol*> vars; list<const Var_symbol*>::const_iterator iter; Matrix *mat; Expr *e; bool zero; vars=globals->symbol_table->get_variables(); res=lhs->get_name() + string(" = "); zero=true; for (iter=vars.begin(); iter!=vars.end(); iter++) { if ( (*iter)->get_kind()!=OUTPUT_KIND ) { mat=find_eq_mat(lhs->get_kind(), lhs->get_type(), (*iter)->get_kind(), (*iter)->get_type()); e=mat->get(lhs->get_count(), (*iter)->get_count()); if (e) { if (!zero) res+=string(" + "); res+=string("("); res+=e->to_matlab(); res+=string(")"); res+=string(" * ") + (*iter)->get_name(); zero=false; delete e; } } } if (globals->cmd_options->consts_in_eq_as_B5D5() && lhs->get_kind()==STATE_KIND) { if (lhs->get_kind()==STATE_KIND) { if (lhs->get_type()==REAL_TYPE) e=B5_r->get(lhs->get_count(), 0); else e=B5_b->get(lhs->get_count(), 0); } else { if (lhs->get_type()==REAL_TYPE) e=D5_r->get(lhs->get_count(), 0); else e=D5_b->get(lhs->get_count(), 0); } if (e) { if (!zero) res+=string(" + "); res+=e->to_matlab(); zero=false; } } if (zero) res+=string("0"); return res;}string MLD_representation::row_to_string(int ineq) const{ string res; list<const Var_symbol*> vars; list<const Var_symbol*>::const_iterator iter; Matrix *mat; Expr *e; bool zero; vars=globals->symbol_table->get_variables(); zero=true; for (iter=vars.begin(); iter!=vars.end(); iter++) { if ( (*iter)->get_kind()!=OUTPUT_KIND ) { mat=find_ineq_mat((*iter)->get_kind(), (*iter)->get_type()); e=mat->get(ineq, (*iter)->get_count()); if (e) { if ( (*iter)->get_kind()==STATE_KIND || (*iter)->get_kind()==INPUT_KIND ) { if (!zero) res+=string(" - "); else res+=string("-"); } else { if (!zero) res+=string(" + "); } res+=string("("); res+=e->to_matlab(); res+=string(")"); res += string(" * ") + (*iter)->get_name(); zero=false; delete e; } } } if (zero) res+=string("0"); res+=string(" <= "); e=E5->get(ineq, 0); if (e) { res+=e->to_matlab(); } else { res+=string("0"); } return res;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -