/** * While inventory/menu is open. */ void DisablePointing() { int i; HPOLYGON hPoly; // Polygon handle g_bPointingActive = false; for (i = 0; i < MAX_POLY; i++) { hPoly = GetPolyHandle(i); if (hPoly != NOPOLY && PolyType(hPoly) == TAG && PolyIsPointedTo(hPoly)) { SetPolyPointedTo(hPoly, false); SetPolyTagWanted(hPoly, false, false, 0); PolygonEvent(Common::nullContext, hPoly, UNPOINT, 0, false, 0); } } // For each tagged actor for (i = 0; (i = NextTaggedActor(i)) != 0; ) { if (ActorIsPointedTo(i)) { SetActorPointedTo(i, false); SetActorTagWanted(i, false, false, 0); ActorEvent(Common::nullContext, i, UNPOINT, false, 0); } } }
std::pair<T, typename SystemIdentification<T>::PolyType> SystemIdentification<T>::CanonicalizePolynomial(const PolyType& poly) { std::vector<MonomialType> monomials = poly.getMonomials(); const T min_coefficient = std::min_element( monomials.begin(), monomials.end(), [&](const MonomialType& l, const MonomialType& r){ return l.coefficient < r.coefficient; })->coefficient; for (MonomialType& monomial : monomials) { monomial.coefficient /= min_coefficient; } return std::make_pair(min_coefficient, PolyType(monomials.begin(), monomials.end())); }
typename SystemIdentification<T>::VarType SystemIdentification<T>::CreateLumpVar( const std::set<VarType>& vars_in_use) { int lump_index = 1; static const std::string kLumpedVariablePrefix = "lump"; while (true) { VarType lump_var = PolyType(kLumpedVariablePrefix, lump_index).getSimpleVariable(); lump_index++; if (!vars_in_use.count(lump_var)) { return lump_var; } } // Loop termination: If every id is already used, PolyType() will throw. }
typename SystemIdentification<T>::PolyType SystemIdentification<T>::RewritePolynomialWithLumpedParameters( const PolyType& poly, const LumpingMapType& lumped_parameters) { // Reconstruct active_vars, the variables in poly that are not // mentioned by the lumped_parameters. std::set<VarType> active_vars = poly.getVariables(); for (const auto& lump_name_pair : lumped_parameters) { std::set<VarType> parameters_in_lump = lump_name_pair.first.getVariables(); for (const VarType& var : parameters_in_lump) { active_vars.erase(var); } } // Loop over the combinations of the active variables, constructing the // polynomial of parameters that multiply by each combination; if that // polynomial is a lumped variable, substitute in a new monomial of the // lumped variable times the combination instead. std::set<MonomialType> active_var_monomials = GetAllCombinationsOfVars({poly}, active_vars); std::vector<MonomialType> working_monomials = poly.getMonomials(); for (const MonomialType& active_var_monomial : active_var_monomials) { // Because we must iterate over working_monomials, we cannot alter it in // place. Instead we build up two lists in parallel: The updated value of // working_monomials (new_working_monomials) unchanged by rewriting and // the monomials of parameter variables that might form the polynomial // of a lumped parameter. // // If (and only if) the polynomial of factored monomials matches a lumped // parameter, we construct a new working_monomials list from the // new_working_monomials list plus a lumped-parameter term. std::vector<MonomialType> new_working_monomials; std::vector<MonomialType> factor_monomials; for (const MonomialType& working_monomial : working_monomials) { if (MonomialMatches(working_monomial, active_var_monomial, active_vars)) { // This monomial matches our active vars monomial; we will factor it // by the active vars monomial and add the resulting monomial of // parameters to our factor list. factor_monomials.push_back( working_monomial.factor(active_var_monomial)); } else { // This monomial does not match our active vars monomial; copy it // unchanged. new_working_monomials.push_back(working_monomial); } } const PolyType factor_polynomial(factor_monomials.begin(), factor_monomials.end()); const auto& canonicalization = CanonicalizePolynomial(factor_polynomial); const T coefficient = canonicalization.first; const PolyType& canonicalized = canonicalization.second; if (!lumped_parameters.count(canonicalized)) { // Factoring out this combination yielded a parameter polynomial that // does not correspond to a lumped variable. Ignore it, because we // cannot rewrite it correctly. // // This can happen if `poly` was not one of the polynomials used to // construct `lumped_parameters`. continue; } // We have a lumped parameter, so construct a new monomial and replace the // working monomials list. TermType lump_term; lump_term.var = lumped_parameters.at(canonicalized); lump_term.power = 1; MonomialType lumped_monomial; lumped_monomial.terms = active_var_monomial.terms; lumped_monomial.terms.push_back(lump_term); lumped_monomial.coefficient = coefficient; new_working_monomials.push_back(lumped_monomial); working_monomials = new_working_monomials; } return PolyType(working_monomials.begin(), working_monomials.end()); }