本文整理汇总了C++中Movement::addMonomial方法的典型用法代码示例。如果您正苦于以下问题:C++ Movement::addMonomial方法的具体用法?C++ Movement::addMonomial怎么用?C++ Movement::addMonomial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Movement
的用法示例。
在下文中一共展示了Movement::addMonomial方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processDynamicActivityNode
DynamicActivity* XmlReader::processDynamicActivityNode(const Node *node) {
const Element *activityElement = castToElement(node);
DynamicActivity *dynamicActivity = new DynamicActivity(stoul(getAttribute(activityElement, "aid")));
dynamicActivity->name(getTextFromElement(activityElement, "name", false));
dynamicActivity->description(getTextFromElement(activityElement, "desc", false));
double minDuration = F64_MAX, maxDuration = F64_MIN;
const Element *movements = castToElement(activityElement->get_first_child("movements"));
string a1 = getAttribute(movements, "from_aid", false), a2 = getAttribute(movements, "to_aid", false);
int64_t fromActivity = (a1.empty() ? -1 : stol(a1)), toActivity = (a2.empty() ? -1 : stol(a2));
const NodeSet movementSet = movements->find("movement");
for (const Node *movementNode : movementSet) {
const Element *movementElement = castToElement(movementNode);
Movement *mv = new Movement(stoul(getAttribute(movementElement, "mid")));
mv->minDuration(stod(getTextFromElement(movementElement, "min-duration")));
mv->maxDuration(stod(getTextFromElement(movementElement, "max-duration")));
if (mv->minDuration() < TIME_ERR) {
string mid = to_string(mv->mid());
delete dynamicActivity;
delete mv;
throw InvalidDatasetFile(caller(), "Dynamic activity's movement "+mid+" must have positive duration!", movementNode->get_line());
}
// Workaround the incapability of ILP solvers to solve the problem with the fixed variables.
if (abs(mv->maxDuration()-mv->minDuration()) < TIME_ERR)
mv->maxDuration(mv->minDuration()+TIME_ERR);
const NodeSet monomials = movementElement->find("energy-function/monomial");
for (const Node *monomialNode : monomials) {
const Element *monomialElement = castToElement(monomialNode);
int32_t degree = stoi(getAttribute(monomialElement, "degree"));
double coeff = stod(getAttribute(monomialElement, "coeff"));
mv->addMonomial({degree, coeff});
}
uint32_t fromPoint = stoul(getTextFromElement(movementElement, "from-point"));
uint32_t toPoint = stoul(getTextFromElement(movementElement, "to-point"));
Location *locFrom = nullptr, *locTo = nullptr;
StaticActivity *actFrom = nullptr, *actTo = nullptr;
auto fSit = mPointToLocation.find(fromPoint), tSit = mPointToLocation.find(toPoint);
if (fSit == mPointToLocation.cend() || tSit == mPointToLocation.cend()) {
delete dynamicActivity;
delete mv;
throw InvalidDatasetFile(caller(), "Dynamic activity's point is not linked with any static activity!", movementNode->get_line());
} else {
locFrom = fSit->second;
locTo = tSit->second;
assert(locFrom != nullptr && locTo != nullptr && "Unexpected null pointers!");
actFrom = locFrom->parent();
actTo = locTo->parent();
assert(actFrom != nullptr && actTo != nullptr && "Should not be nullptr as it has been set in processRobotNode method!");
}
if ((actFrom->aid() != fromActivity && fromActivity != -1) || (actTo->aid() != toActivity && toActivity != -1)) {
delete dynamicActivity;
delete mv;
throw InvalidDatasetFile(caller(), "Optional attributes 'from_aid' and/or 'to_aid' are invalid!", movementNode->get_line());
}
minDuration = min(minDuration, mv->minDuration());
maxDuration = max(maxDuration, mv->maxDuration());
setValue(mMovementToPoints, mv, {fromPoint, toPoint}, caller());
dynamicActivity->addMovement(mv);
}
dynamicActivity->minAbsDuration(minDuration);
dynamicActivity->maxAbsDuration(maxDuration);
return dynamicActivity;
}