void Master::treeInterfaceNodeBounds(int id, double lb, double ub) { if (VbcLog_ == NoVbc) return; //char string[256]; ostringstream info; if (isInfinity(fabs(lb))) { if (isInfinity(fabs(ub))) info << "I " << id << " \\iLower Bound: ---\\nUpper Bound: ---\\i"; else info << "I " << id << " \\iLower Bound: ---\\nUpper Bound: " << std::ios::fixed << std::setprecision(2) << std::setw(6) << ub << "\\i"; } else { if (isInfinity(fabs(ub))) info << "I " << id << " \\iLower Bound: " << std::ios::fixed << std::setprecision(2) << std::setw(6) << lb << "\\nUpper Bound: ---\\i"; else info << "I " << id << " \\iLower Bound: " << std::ios::fixed << std::setprecision(2) << std::setw(6) << lb << "\\nUpper Bound: " << std::ios::fixed << std::setprecision(2) << std::setw(6) << ub << "\\i"; } writeTreeInterface(info.str()); }
void Coordinator::processInit(Simulator* simulator) { Time tn = simulator->init(m_currentTime); if (not isInfinity(tn)) { m_eventTable.addInternal(simulator, tn); } }
InternalEvent * Simulator::buildInternalEvent(const Time& currentTime) { Time time(timeAdvance()); if (not isInfinity(time)) { return new InternalEvent(currentTime + time, this); } else { return 0; } }
InternalEvent* Simulator::init(const Time& currentTime) { Time time(m_dynamics->init(currentTime)); if (not isInfinity(time)) { return new InternalEvent(currentTime + time, this); } else { return 0; } }
unsigned int floatToUint (float f) { if (isNegative (f) || isNan (f)) return 0; if (isInfinity (f) || f > UINT_MAX) return UINT_MAX; return (unsigned int) f; }
string Cost::toString(CostType costType) const { if (!isInfinity() && costType == CompressionCost) { return SpritePack::toString((double)value / 1000.0, 1) + "ms"; } else { return Number::toString(); } }
void NominalEventMonitor::stopMonitor() { stopped = true; if (running) { running = false; if (isInfinity(expectedSleepTime) || paused) { unlockConditionSatisfied(); } else { wakeUp(); } } }
bool RootCoordinator::run() { m_currentTime = m_coordinator->getCurrentTime(); if (isInfinity(m_currentTime)) return false; if ((m_end - m_currentTime) < 0) return false; m_coordinator->run(); return true; }
void NominalEventMonitor::prepareNptTransitionsEvents() { AttributionEvent* event; set<double>* transValues; set<double>::iterator i; executionObject->prepareTransitionEvents( ContentAnchor::CAT_NPT, timeBaseProvider->getCurrentTimeValue(timeBaseId)); transValues = executionObject->getTransitionsValues( ContentAnchor::CAT_NPT); if (transValues == NULL || transValues->empty()) { cout << "NominalEventMonitor::prepareNptTransitionsEvents "; cout << "nothing to do (2)." << endl; return; } executionObject->updateTransitionTable( timeBaseProvider->getCurrentTimeValue(timeBaseId), NULL, ContentAnchor::CAT_NPT); i = transValues->begin(); while (i != transValues->end()) { if (!isInfinity(*i)) { /*cout << "NominalEventMonitor::prepareNptTransitionsEvents "; cout << "add listener contentId '" << timeBaseId; cout << "' for value '" << *i; cout << "' (current time = '"; cout << timeBaseProvider->getCurrentTimeValue(timeBaseId); cout << "')" << endl;*/ timeBaseProvider->addTimeListener(timeBaseId, *i, this); } ++i; } delete transValues; event = (AttributionEvent*)(executionObject->getEventFromAnchorId( "contentId")); if (event != NULL) { adapter->setPropertyValue(event, itos(timeBaseId), NULL); event->stop(); } }
void NominalEventMonitor::stopMonitor() { stopped = true; if (timeBaseProvider != NULL) { timeBaseProvider->removeTimeListener(timeBaseId, this); timeBaseProvider->removeIdListener(this); } if (running) { running = false; if (isInfinity(expectedSleepTime) || paused) { unlockConditionSatisfied(); } else { wakeUp(); } } }
string FlexibleTimeMeasurement::toString() { return ( "expected value: " + itos(expectedValue) + "; actual value: " + (isNaN(actualValue) ? "UNDEFINED" : "" + itos(actualValue))) + ( "; minimum value: " + itos(minimumValue) + "; maximum value : " + (isInfinity(maximumValue) ? "INFINITY" : "" + itos(maximumValue)) + "; computed value: " + (isNaN(computedValue) ? "UNDEFINED" : "" + itos(computedValue))); }
std::string DecimalDecNumber::toStringAllowScientific(uint32 decimalPlaces) const { if (!isZero() && !isInfinity() && !decNumberIsNaN(&m_value)) { static const int BUFFER_SIZE = 256; char buffer[BUFFER_SIZE]; { DecimalDecNumber rounded(*this); rounded.round(decimalPlaces, RoundingMode::ROUND_TO_ZERO); decNumberToString(&rounded.m_value, buffer); } char * e = buffer + strlen(buffer); char * f = std::find(buffer, e, '+'); if (f != e) return buffer; } return toString(decimalPlaces); }
string LinearCostFunctionDuration::toString() { return ( ( "expected value: " + itos(expectedValue) + "; actual value: " + (!isNaN(actualValue) ? "UNDEFINED" : "" + itos(actualValue))) + ("; minimum value: " + itos(minimumValue) + "; maximum value : " + (isInfinity(maximumValue) ? "INFINITY" : "" + itos(maximumValue)) + "; computed value: " + (!isNaN(computedValue) ? "UNDEFINED" : "" + itos(computedValue))) + "; shrinking cost rate: " + itos(getShrinkingCostRate()) + "; stretching cost rate: " + itos(getStretchingCostRate())); }
int ss_func( const gsl_vector* x, void* params, gsl_vector* f ) { struct reac_info* ri = (struct reac_info *)params; // Stoich* s = reinterpret_cast< Stoich* >( ri->stoich.eref().data() ); int num_consv = ri->num_mols - ri->rank; for ( unsigned int i = 0; i < ri->num_mols; ++i ) { double temp = op( gsl_vector_get( x, i ) ); if ( isNaN( temp ) || isInfinity( temp ) ) { return GSL_ERANGE; } else { ri->nVec[i] = temp; } } vector< double > vels; ri->pool->updateReacVelocities( &ri->nVec[0], vels ); assert( vels.size() == static_cast< unsigned int >( ri->num_reacs ) ); // y = Nr . v // Note that Nr is row-echelon: diagonal and above. for ( int i = 0; i < ri->rank; ++i ) { double temp = 0; for ( int j = i; j < ri->num_reacs; ++j ) temp += gsl_matrix_get( ri->Nr, i, j ) * vels[j]; gsl_vector_set( f, i, temp ); } // dT = gamma.S - T for ( int i = 0; i < num_consv; ++i ) { double dT = - ri->T[i]; for ( unsigned int j = 0; j < ri->num_mols; ++j ) dT += gsl_matrix_get( ri->gamma, i, j) * op( gsl_vector_get( x, j ) ); gsl_vector_set( f, i + ri->rank, dT ); } return GSL_SUCCESS; }
void Coordinator::run() { Bag& bag = m_eventTable.getCurrentBag(); if (not bag.dynamics.empty() or not bag.executives.empty()) m_currentTime = m_eventTable.getCurrentTime(); else vDbg(m_context, "Coordinator::run bag is empty...\n"); vDbg(m_context, _("-------- BAG [%f] --------\n"), m_currentTime); // // Call output functions for all executives and dynamics models then // dispatches external events for all executives and dynamics. // const std::size_t nb_dynamics = bag.dynamics.size(); const std::size_t nb_executive = bag.executives.size(); if (nb_dynamics > 0) { for (std::size_t i = 0; i != nb_dynamics; ++i) bag.dynamics[i]->output(m_currentTime); dispatchExternalEvent(bag.dynamics, nb_dynamics); } if (nb_executive > 0) { for (std::size_t i = 0; i != nb_executive; ++i) bag.executives[i]->output(m_currentTime); dispatchExternalEvent(bag.executives, nb_executive); } // // First we sort executives models according to the depth of the executive // model into the structure of the models. // if (not bag.executives.empty()) { std::sort(bag.executives.begin(), bag.executives.end(), [](const Simulator* lhs, const Simulator* rhs) { return ::depth(lhs->dynamics()) < ::depth(rhs->dynamics()); }); } // // Compute internal, confluent or external transition for dynamics models. // If parallelization is available, use it otherwise, compute transition // linearly. // if (m_simulators_thread_pool.parallelize()) { m_simulators_thread_pool.for_each(bag.dynamics, m_currentTime); } else { for (auto& elem : bag.dynamics) { if (elem->haveInternalEvent()) { if (not elem->haveExternalEvents()) elem->internalTransition(m_currentTime); else elem->confluentTransitions(m_currentTime); } else { elem->externalTransition(m_currentTime); } } } for (auto& elem : bag.dynamics) { auto tn = elem->getTn(); if (not isInfinity(tn)) m_eventTable.addInternal(elem, tn); } for (auto& elem : bag.executives) { if (elem->haveInternalEvent()) { if (not elem->haveExternalEvents()) elem->internalTransition(m_currentTime); else elem->confluentTransitions(m_currentTime); } else { elem->externalTransition(m_currentTime); } } for (auto& elem : bag.executives) { auto tn = elem->getTn(); if (not isInfinity(tn)) m_eventTable.addInternal(elem, tn); } // // Finally, we go through simulators and executive to get all observation // and dispatch to output plug-in. // for (auto& elem : bag.dynamics) { auto& observations = elem->getObservations(); for (auto& obs : observations) obs.view->run(elem->dynamics().get(), m_currentTime, obs.portname, std::move(obs.value)); observations.clear(); } for (auto& elem : bag.executives) { auto& observations = elem->getObservations(); for (auto& obs : observations) obs.view->run(elem->dynamics().get(), m_currentTime, obs.portname, std::move(obs.value)); observations.clear(); } // // Process observation event if the next bag is scheduled for a different // date than \e m_currentTime. // auto next = m_eventTable.getNextTime(); if (next > m_currentTime) { // // Scheduler is empty. We eat all timed view until the duration time // auto eatuntil = std::min(next, m_durationTime); while (m_timed_observation_scheduler.haveObservationAtTime(eatuntil)) { auto obs = m_timed_observation_scheduler.getObservationAtTime(eatuntil); if (not obs.empty()) { m_currentTime = obs.back().mTime; for (auto& elem : obs) { elem.run(); elem.update(); if (not isInfinity(elem.mTime)) m_timed_observation_scheduler.add( elem.mView, elem.mTime, elem.mTimestep); } } } if (isInfinity(next) or next > m_durationTime) { // // For all Timed view, process a final observation and clear the // scheduler. // m_currentTime = m_durationTime; m_timed_observation_scheduler.finalize(m_currentTime); } } // // Finally, we destroy model and simulator if one executive delete a model // if (not m_delete_model.empty()) dynamic_deletion(); m_eventTable.makeNextBag(); m_currentTime = m_eventTable.getCurrentTime(); }
void NominalEventMonitor::resumeMonitor() { if (!isInfinity(expectedSleepTime) && paused) { paused = false; unlockConditionSatisfied(); } }
bool IntervalAnchor::isObjectDuration(double value) { return isInfinity(value); }
void NominalEventMonitor::run() { lock(); EventTransition* nextTransition; double time; double mediaTime = 0; double nextEntryTime; nextTransition = NULL; /*cout << "====== Anchor Monitor Activated for '"; cout << executionObject->getId().c_str() << "' ("; cout << this << " ======" << endl;*/ while (running) { if (deleting) { break; } if (paused) { waitForUnlockCondition(); } else { if (executionObject != NULL) { nextTransition = executionObject->getNextTransition(); } else { nextTransition = NULL; running = false; } if (nextTransition == NULL) { running = false; } else { nextEntryTime = nextTransition->getTime(); if (isInfinity(nextEntryTime)) { expectedSleepTime = infinity(); } else { mediaTime = (adapter->getPlayer()->getMediaTime() * 1000); expectedSleepTime = nextEntryTime - mediaTime; } /*cout << "ANCHORMONITOR NEXTTRANSITIONTIME = '"; cout << nextEntryTime << "' MEDIATIME = '" << mediaTime; cout << "' EXPECTEDSLEEPTIME = '" << expectedSleepTime; cout << "' (" << this << ")" << endl;*/ if (running && !deleting) { if (isInfinity(expectedSleepTime)) { waitForUnlockCondition(); } else { Thread::usleep((int)(expectedSleepTime)); } if (running && !deleting) { if (executionObject == NULL || adapter == NULL) { unlock(); return; } mediaTime = (adapter->getPlayer()->getMediaTime() * 1000); time = nextEntryTime - mediaTime; if (time < 0) { time = 0; } if (!paused && time <= DEFAULT_ERROR) { // efetua a transicao no estado do evento executionObject->updateTransitionTable( mediaTime + DEFAULT_ERROR, adapter->getPlayer(), ContentAnchor::CAT_TIME); } } } } } } if (!stopped && adapter != NULL && !deleting) { adapter->getPlayer()->forceNaturalEnd(); } unlock(); }
void NominalEventMonitor::pauseMonitor() { if (!isInfinity(expectedSleepTime)) { wakeUp(); paused = true; } }
// Lalit: toString should "truncate" values rather than round std::string DecimalDecNumber::toString(uint32 decimalPlaces) const { // Remove these statics if we ever get a short string optimisation in place (gcc 4.1) static const std::string zero = "0.0"; static const std::string posinf = "+INF"; static const std::string neginf = "-INF"; static const std::string nan = "NaN"; if (isZero()) return zero; else if (isInfinity()) { return isNegative() ? neginf : posinf; } else if (decNumberIsNaN(&m_value)) { // TODO: is it possible to have positive/negative nans? return nan; } static const int BUFFER_SIZE = 256; char buffer[BUFFER_SIZE]; { DecimalDecNumber rounded(*this); rounded.round(decimalPlaces, RoundingMode::ROUND_TO_ZERO); decNumberToString(&rounded.m_value, buffer); } // printf("after round: %s\n", buffer); char * b = buffer; char * e = buffer + strlen(buffer); unpackScientificFormat(b, e, BUFFER_SIZE, decimalPlaces); if ((e-b) == 3 && strcmp(buffer, "NaN") == 0) { return buffer; } else if (std::find(b, e, '.') == e) { strcpy(e, ".0"); return buffer; } { // This code makes the unit tests pass (which were based on the old Decimal implementation) // Ensure that there are no trailing zeros, except when the value is an integer, in which case there should be one trailing zero. char * lastNonZeroDigitAfterDecimal = e - 1; while (*lastNonZeroDigitAfterDecimal == '0') { --lastNonZeroDigitAfterDecimal; } if (*lastNonZeroDigitAfterDecimal == '.') { *(++lastNonZeroDigitAfterDecimal) = '0'; } *(lastNonZeroDigitAfterDecimal + 1) = 0; } // printf("last return\n"); return buffer; }