void analyze() { double *sum = new double[algorithm->getMeasureCount()]; double *sumSquared = new double[algorithm->getMeasureCount()]; for(long time = 0; time < algorithm->getMeasureCount(); time++) { sum[time] = (time == 0 ? 0 : sum[time - 1]) + getQuantity(time); sumSquared[time] = (time == 0 ? 0 : sumSquared[time - 1]) + pow(getQuantity(time), 2); } for(autoCorrelationTime = 0; autoCorrelationTime < algorithm->getMeasureCount(); autoCorrelationTime++) { double sumP = 0; for(long time = 0; time < algorithm->getMeasureCount() - autoCorrelationTime; time++) { sumP += getQuantity(time) * getQuantity(time + autoCorrelationTime); } long timeToAverage = algorithm->getMeasureCount() - autoCorrelationTime; double autoCorrelation = ((sumP / timeToAverage) - pow(sum[algorithm->getMeasureCount() - 1] / timeToAverage, 2)) / ((sumSquared[algorithm->getMeasureCount() - 1] / timeToAverage) - pow(sum[algorithm->getMeasureCount() - 1] / timeToAverage, 2)); if(isnan(autoCorrelation)) { printf("# %s at temperature=%+20.13e was not measured, due to the unknown relaxation time\n", getQuantityName(), algorithm->getTemperature()); autoCorrelationTime = -1; break; } printf("# Auto-Correlation of %s=%+20.13e\n", getQuantityName(), autoCorrelation); if(autoCorrelation < exp(-1)) break; } autoCorrelationTime++; if(autoCorrelationTime != 0) { long binsCount = algorithm->getMeasureCount() / 3 / autoCorrelationTime; double *binAverage = new double[binsCount]; for(long bin = 0; bin < binsCount; bin++) { binAverage[bin] = (sum[(bin + 1) * 3 * autoCorrelationTime] - sum[bin * 3 * autoCorrelationTime]) / 3 / autoCorrelationTime; average += binAverage[bin] / binsCount; } double deviationSum = 0; for(long bin = 0; bin < binsCount; bin++) { deviationSum += pow(binAverage[bin] - average, 2); } error = sqrt(deviationSum / binsCount / (binsCount - 1)); delete[] binAverage; } delete[] sum; delete[] sumSquared; };
/** * Increases the quantity of the selected item to sell by "change". * @param change how much we want to add */ void SellState::increase(int change) { if (0 >= change || getQuantity() <=_qtys[_sel]) return; change = std::min(getQuantity() - _qtys[_sel], change); _qtys[_sel] += change; _total += getPrice() * change; updateItemStrings(); }
/** * Increases or decreases the quantity of the selected item to sell. * @param change How much we want to add or remove. * @param dir Direction to change, +1 to increase or -1 to decrease. */ void SellState::changeByValue(int change, int dir) { if (dir > 0) { if (0 >= change || getQuantity() <=_qtys[_sel]) return; change = std::min(getQuantity() - _qtys[_sel], change); } else { if (0 >= change || 0 >= _qtys[_sel]) return; change = std::min(_qtys[_sel], change); } _qtys[_sel] += dir * change; _total += dir * getPrice() * change; // Calculate the change in storage space. Craft *craft; RuleItem *armor, *item, *weapon, *ammo; double total = 0.0; switch (getType(_sel)) { case SELL_SOLDIER: if (_soldiers[_sel]->getArmor()->getStoreItem() != "STR_NONE") { armor = _game->getRuleset()->getItem(_soldiers[_sel]->getArmor()->getStoreItem()); _spaceChange += dir * armor->getSize(); } break; case SELL_CRAFT: craft = _crafts[getCraftIndex(_sel)]; for (std::vector<CraftWeapon*>::iterator w = craft->getWeapons()->begin(); w != craft->getWeapons()->end(); ++w) { if (*w) { weapon = _game->getRuleset()->getItem((*w)->getRules()->getLauncherItem()); total += weapon->getSize(); ammo = _game->getRuleset()->getItem((*w)->getRules()->getClipItem()); if (ammo) total += ammo->getSize() * (*w)->getClipsLoaded(_game->getRuleset()); } } _spaceChange += dir * total; break; case SELL_ITEM: item = _game->getRuleset()->getItem(_items[getItemIndex(_sel)]); _spaceChange -= dir * change * item->getSize(); break; default: break; } updateItemStrings(); }
void Kit::ingestCsvInput(std::vector<std::vector<std::string>> csvFieldList) { std::vector<std::string> csvField; std::string firstField; std::string quantity; std::string partNumber; std::string description; int line; for (int i = 0; i < csvFieldList.size(); i++) { line = i; csvField = csvFieldList[i]; if (line == 0) { firstField = csvField[0]; setKitName(firstField); } //checks if field is size 3 and if not header if (csvField.size() >= 3 && csvField[0] != "Qty") { quantity = csvField[0]; partNumber = csvField[1]; description = csvField[2]; setQuantity(quantity); setPartNumber(partNumber); setDescription(description); setAttributes(getQuantity(), getDescription()); addParts(); } } }//end ingestCsvInput()
/** * Increases the quantity of the selected item to sell. */ void SellState::increase() { if (_qtys[_sel] < getQuantity()) { _qtys[_sel]++; std::wstringstream ss, ss2; ss << _qtys[_sel]; _lstItems->setCellText(_sel, 2, ss.str()); ss2 << getQuantity() - _qtys[_sel]; _lstItems->setCellText(_sel, 1, ss2.str()); _total += getPrice(); std::wstring s = _game->getLanguage()->getString("STR_VALUE_OF_SALES"); s += Text::formatFunding(_total); _txtSales->setText(s); } }
String Card::getAll() { String all = getQuantity()+","+getText()+","+getThumb()+","+getFront()+ ","+getBack()+","+getId()+","+getRate()+","+getValue()+","+getNote()+","+getOrientation()+","; for (int i = 0; i < stats.size(); i++) { all += stats[i]->getAll() + "$"; } return all; }
/** * Increases the quantity of the selected alien to exterminate by "change". * @param change How much we want to add. */ void ManageAlienContainmentState::increaseByValue(int change) { int qty = getQuantity() - _qtys[_sel]; if (change <= 0 || qty <= 0) return; change = std::min(qty, change); _qtys[_sel] += change; _aliensSold += change; updateStrings(); }
/** * Increase the item to max on right-click. * @param action Pointer to an action. */ void SellState::lstItemsLeftArrowClick(Action *action) { if (action->getDetails()->button.button == SDL_BUTTON_RIGHT) { if (_qtys[_sel] < getQuantity()) { int change = getQuantity() - _qtys[_sel]; _qtys[_sel] = getQuantity(); std::wstringstream ss, ss2; ss << _qtys[_sel]; _lstItems->setCellText(_sel, 2, ss.str()); ss2 << 0; _lstItems->setCellText(_sel, 1, ss2.str()); _total += getPrice() * change; std::wstring s = _game->getLanguage()->getString("STR_VALUE_OF_SALES"); s += Text::formatFunding(_total); _txtSales->setText(s); } } }
//Displas Book`s detail void book::display(){ cout<<"\nBook`s Detail:-"; cout<<"\nItem ID:"<<getID(); cout<<"\nTitle:"<<getTitle(); cout<<"\nPrice:RM"<<getPrice(); cout<<"\nQuantity:"<<getQuantity(); cout<<"\nAuthor:"<<getAuthor(); cout<<"\nPublisher:"<<getPublisher(); cout<<"\nISBN:"<<getISBN(); cout<<endl; }
void ResourceContainerImplementation::combine(ResourceContainer* fromContainer) { Locker _locker(_this.get()); ManagedReference<SceneObject*> parent = fromContainer->getParent(); setQuantity(getQuantity() + fromContainer->getQuantity()); fromContainer->setQuantity(0); //parent->removeObject(fromContainer, true); fromContainer->destroyObjectFromWorld(true); fromContainer->destroyObjectFromDatabase(true); }
void Card::setAll(const char* allch) { String all = allch; int indexof = all.find(delim); if (indexof > -1) { setQuantity(all.substr(0,indexof++).c_str()); all=all.substr(indexof); indexof = all.find(delim); setText(all.substr(0,indexof++).c_str()); all=all.substr(indexof); indexof = all.find(delim); setThumb(all.substr(0,indexof++).c_str()); all=all.substr(indexof); indexof = all.find(delim); setFront(all.substr(0,indexof++).c_str()); all=all.substr(indexof); indexof = all.find(delim); setBack(all.substr(0,indexof++).c_str()); all=all.substr(indexof); indexof = all.find(delim); setId(all.substr(0,indexof++).c_str()); all=all.substr(indexof); indexof = all.find(delim); setRate(all.substr(0,indexof++).c_str()); all=all.substr(indexof); indexof = all.find(delim); setValue(all.substr(0,indexof++).c_str()); all=all.substr(indexof); indexof = all.find(delim); setNote(all.substr(0,indexof++).c_str()); all=all.substr(indexof); setLoaded(true); if ((getText().length() <= 0)||(getQuantity().length() <= 0)) { setQuantity(""); setText(""); setLoaded(false); } } else { setQuantity(""); setText(""); setThumb(""); setFront(""); setBack(""); setId(""); setRate(""); setValue(""); setNote(""); setLoaded(false); } }
void Ingredient::removeUnits( int quantityToRemove ) { /// WARNING /// /// THIS METHOD DOES /// /// NOT CHECK IF IT /// /// IS TAKING MORE /// /// THAN WHAT IS IN /// /// STOCK /// /// IT WILL SET /// /// QUANTITY TO /// ///____ZERO_____/// /// WARNING /// setQuantity( getQuantity() - quantityToRemove ); }
void ResourceContainerImplementation::split(int newStackSize) { if (getQuantity() <= newStackSize) return; if(newStackSize > getQuantity()) newStackSize = getQuantity(); ManagedReference<ResourceContainer*> newResource = spawnObject->createResource(newStackSize); if(parent == NULL || newResource == NULL || newResource->getSpawnObject() == NULL) return; ManagedReference<SceneObject*> sceneParent = cast<SceneObject*>(parent.get().get()); if(sceneParent->transferObject(newResource, -1, true)) { sceneParent->broadcastObject(newResource, true); setQuantity(getQuantity() - newStackSize); } else { StringBuffer errorMessage; errorMessage << "Unable to split resource in container type: " << sceneParent->getGameObjectType() << " " << sceneParent->getDisplayedName(); error(errorMessage.toString()); } }
void ResourceContainerImplementation::split(int newStackSize, CreatureObject* player) { ManagedReference<SceneObject*> inventory = player->getSlottedObject("inventory"); ManagedReference<ResourceContainer*> newResource = spawnObject->createResource(newStackSize); if (newResource == NULL || newResource->getSpawnObject() == NULL) return; if(inventory->transferObject(newResource, -1, true)) { newResource->sendTo(player, true); setQuantity(getQuantity() - newStackSize); } else { error("Unable to split resource to player: " + player->getFirstName()); } }
DECLARE_EXPORT void Flow::setAlternate(Flow *f) { // Can't be an alternate to oneself. // No need to flag as an exception. if (f == this) return; // Validate the argument if (!f) throw DataException("Setting NULL alternate flow"); if (hasAlts || f->altFlow) throw DataException("Nested alternate flows are not allowed"); if (f->getQuantity() > 0.0 || getQuantity() > 0.0) throw DataException("Only consuming alternate flows are supported"); // Update both flows f->hasAlts = true; altFlow = f; }
pair<Date, double> FlowEnd::getFlowplanDateQuantity(const FlowPlan* fl) const { if (isConsumer() && !fl->getOperationPlan()->getConsumeMaterial()) return make_pair(fl->getOperationPlan()->getEnd(), 0.0); else if (isProducer() && !fl->getOperationPlan()->getProduceMaterial()) return make_pair(fl->getOperationPlan()->getEnd(), 0.0); else if (fl->getConfirmed()) return make_pair( fl->getOperationPlan()->getEnd(), fl->getQuantity() ); else return make_pair( fl->getOperationPlan()->getEnd(), getEffective().within(fl->getDate()) && fl->getOperationPlan()->getQuantity() ? getQuantityFixed() + fl->getOperationPlan()->getQuantity() * getQuantity() : 0.0 ); }
PyObject* FlowPlan::getattro(const Attribute& attr) { if (attr.isA(Tags::tag_operationplan)) return PythonObject(getOperationPlan()); if (attr.isA(Tags::tag_quantity)) return PythonObject(getQuantity()); if (attr.isA(Tags::tag_flow)) return PythonObject(getFlow()); if (attr.isA(Tags::tag_date)) return PythonObject(getDate()); if (attr.isA(Tags::tag_onhand)) return PythonObject(getOnhand()); if (attr.isA(Tags::tag_buffer)) // Convenient shortcut return PythonObject(getFlow()->getBuffer()); if (attr.isA(Tags::tag_operation)) // Convenient shortcut return PythonObject(getFlow()->getOperation()); return NULL; }
/** * Updates the quantity-strings of the selected alien. */ void ManageAlienContainmentState::updateStrings() { std::wostringstream ss, ss2, ss3; int qty = getQuantity() - _qtys[_sel]; ss << qty; ss2 << _qtys[_sel]; _lstAliens->setRowColor(_sel, (qty != 0)? _color2 : _color); _lstAliens->setCellText(_sel, 1, ss.str()); _lstAliens->setCellText(_sel, 2, ss2.str()); int aliens = _base->getUsedContainment() - _aliensSold - _researchedAliens; int spaces = _base->getAvailableContainment() - _base->getUsedContainment() + _aliensSold; bool enoughSpace = Options::storageLimitsEnforced ? spaces >= 0 : true; _btnCancel->setVisible(!_overCrowded); _btnOk->setVisible(enoughSpace); _txtAvailable->setText(tr("STR_SPACE_AVAILABLE").arg(spaces)); _txtUsed->setText(tr("STR_SPACE_USED").arg(aliens)); }
/** * Updates the quantity-strings of the selected alien. */ void ManageAlienContainmentState::updateStrings() { std::wostringstream ss, ss2, ss3; int qty = getQuantity() - _qtys[_sel]; ss << qty; ss2 << _qtys[_sel]; _lstAliens->setRowColor(_sel, (qty == 0)? _lstAliens->getSecondaryColor() : _lstAliens->getColor()); _lstAliens->setCellText(_sel, 1, ss.str()); _lstAliens->setCellText(_sel, 2, ss2.str()); int aliens = _base->getUsedContainment() - _aliensSold; int spaces = _base->getAvailableContainment() - aliens; if (Options::storageLimitsEnforced) { _btnOk->setVisible(spaces >= 0); } _txtAvailable->setText(tr("STR_SPACE_AVAILABLE").arg(spaces)); _txtUsed->setText(tr("STR_SPACE_USED").arg(aliens)); }
/** * Updates the quantity-strings of the selected item. */ void SellState::updateItemStrings() { std::wostringstream ss, ss2, ss5; ss << _qtys[_sel]; _lstItems->setCellText(_sel, 2, ss.str()); ss2 << getQuantity() - _qtys[_sel]; _lstItems->setCellText(_sel, 1, ss2.str()); _txtSales->setText(tr("STR_VALUE_OF_SALES").arg(Text::formatFunding(_total))); if (_qtys[_sel] > 0) { _lstItems->setRowColor(_sel, _lstItems->getSecondaryColor()); } else { _lstItems->setRowColor(_sel, _lstItems->getColor()); if (_sel > _itemOffset) { RuleItem *rule = _game->getRuleset()->getItem(_items[_sel - _itemOffset]); if (rule->getBattleType() == BT_AMMO || (rule->getBattleType() == BT_NONE && rule->getClipSize() > 0)) { _lstItems->setRowColor(_sel, _ammoColor); } } } ss5 << _base->getUsedStores(); if (std::abs(_spaceChange) > 0.05) { ss5 << "("; if (_spaceChange > 0.05) ss5 << "+"; ss5 << std::fixed << std::setprecision(1) << _spaceChange << ")"; } ss5 << ":" << _base->getAvailableStores(); _txtSpaceUsed->setText(tr("STR_SPACE_USED").arg(ss5.str())); if (Options::storageLimitsEnforced) { _btnOk->setVisible(!_base->storesOverfull(_spaceChange)); } }
// Remember that this method only superficially looks like a normal // writeElement() method. DECLARE_EXPORT void FlowPlan::writeElement(XMLOutput *o, const Keyword& tag, mode m) const { o->BeginObject(tag); o->writeElement(Tags::tag_date, getDate()); o->writeElement(Tags::tag_quantity, getQuantity()); o->writeElement(Tags::tag_onhand, getOnhand()); o->writeElement(Tags::tag_minimum, getMin()); o->writeElement(Tags::tag_maximum, getMax()); if (!dynamic_cast<OperationPlan*>(o->getCurrentObject())) o->writeElement(Tags::tag_operationplan, &*getOperationPlan()); // Write pegging info. if (o->getContentType() == XMLOutput::PLANDETAIL) { // Write the upstream pegging PeggingIterator k(this, false); if (k) --k; for (; k; --k) o->writeElement(Tags::tag_pegging, Tags::tag_level, -k.getLevel(), Tags::tag_operationplan, k.getOperationPlan()->getIdentifier(), Tags::tag_quantity, k.getQuantity() ); // Write the downstream pegging PeggingIterator l(this, true); if (l) ++l; for (; l; ++l) o->writeElement(Tags::tag_pegging, Tags::tag_level, l.getLevel(), Tags::tag_operationplan, l.getOperationPlan()->getIdentifier(), Tags::tag_quantity, l.getQuantity() ); } o->EndObject(tag); }
DECLARE_EXPORT void Demand::updateProblems() { // The relation between the demand and the related problem classes is such // that the demand object is the only active one. The problem objects are // fully controlled and managed by the associated demand object. // A flag for each problem type that may need to be created bool needsNotPlanned(false); bool needsEarly(false); bool needsLate(false); bool needsShort(false); bool needsExcess(false); // Problem detection disabled on this demand if (!getDetectProblems()) return; // Check which problems need to be created if (deli.empty()) { // Check if a new ProblemDemandNotPlanned needs to be created if (getQuantity()>0.0) needsNotPlanned = true; } else { // Loop through the deliveries for (OperationPlanList::iterator i = deli.begin(); i!=deli.end(); ++i) { // Check for ProblemLate problem long d(getDue() - (*i)->getDates().getEnd()); if (d < 0L) needsLate = true; // Check for ProblemEarly problem else if (d > 0L) needsEarly = true; } // Check for ProblemShort problem double plannedqty = getPlannedQuantity(); if (plannedqty + ROUNDING_ERROR < qty) needsShort = true; // Check for ProblemExcess Problem if (plannedqty - ROUNDING_ERROR > qty) needsExcess = true; } // Loop through the existing problems for (Problem::iterator j = Problem::begin(this, false); j!=Problem::end(); ) { // Need to increment now and define a pointer to the problem, since the // problem can be deleted soon (which invalidates the iterator). Problem& curprob = *j; ++j; // The if-statement keeps the problem detection code concise and // concentrated. However, a drawback of this design is that a new Problem // subclass will also require a new Demand subclass. I think such a link // is acceptable. if (typeid(curprob) == typeid(ProblemEarly)) { // if: problem needed and it exists already if (needsEarly) needsEarly = false; // else: problem not needed but it exists already else delete &curprob; } else if (typeid(curprob) == typeid(ProblemDemandNotPlanned)) { if (needsNotPlanned) needsNotPlanned = false; else delete &curprob; } else if (typeid(curprob) == typeid(ProblemLate)) { if (needsLate) needsLate = false; else delete &curprob; } else if (typeid(curprob) == typeid(ProblemShort)) { if (needsShort) needsShort = false; else delete &curprob; } else if (typeid(curprob) == typeid(ProblemExcess)) { if (needsExcess) needsExcess = false; else delete &curprob; } // Note that there may be other demand exceptions that are not caught in // this loop. These are problems defined and managed by subclasses. } // Create the problems that are required but aren't existing yet. if (needsNotPlanned) new ProblemDemandNotPlanned(this); if (needsLate) new ProblemLate(this); if (needsEarly) new ProblemEarly(this); if (needsShort) new ProblemShort(this); if (needsExcess) new ProblemExcess(this); }
pair<Date, double> FlowTransferBatch::getFlowplanDateQuantity(const FlowPlan* fl) const { double batch_quantity = getTransferBatch(); if (!batch_quantity || fl->getOperationPlan()->getSetupEnd() == fl->getOperationPlan()->getEnd()) // Default to a simple flowplan at the start or end return make_pair( isConsumer() ? fl->getOperationPlan()->getSetupEnd() : fl->getOperationPlan()->getEnd(), getQuantityFixed() + getQuantity() * fl->getOperationPlan()->getQuantity() ); // Compute the number of batches double total_quantity = getQuantityFixed() + fl->getOperationPlan()->getQuantity() * getQuantity(); if (isConsumer() && !fl->getOperationPlan()->getConsumeMaterial()) total_quantity = 0.0; else if (isProducer() && !fl->getOperationPlan()->getProduceMaterial()) total_quantity = 0.0; double batches = ceil((getQuantity() > 0 ? total_quantity : -total_quantity) / getTransferBatch()); if (!batches) batches = 1; else if (batches > 50) { // Put a limit to the number of batches batches = 50; batch_quantity = (getQuantity() > 0 ? total_quantity : -total_quantity) / 50; } // Count the index of this batch bool found = false; long count = 0; long totalcount = 0; FlowPlan* cur_flpln = fl->getOperationPlan()->firstflowplan; FlowPlan* prev_flpln = nullptr; while (cur_flpln) { if (cur_flpln == fl) found = true; if (cur_flpln->getFlow() == fl->getFlow()) { ++totalcount; if (totalcount > batches && !count) { if (cur_flpln->oper->firstflowplan == cur_flpln) cur_flpln->oper->firstflowplan = cur_flpln->nextFlowPlan; else prev_flpln->nextFlowPlan = cur_flpln->nextFlowPlan; auto almost_dead = cur_flpln; cur_flpln = cur_flpln->nextFlowPlan; delete almost_dead; continue; } if (!found) ++count; } prev_flpln = cur_flpln; cur_flpln = cur_flpln->nextFlowPlan; } Duration op_delta; Date op_date = fl->getOperation()->calculateOperationTime( fl->getOperationPlan(), fl->getOperationPlan()->getSetupEnd(), fl->getOperationPlan()->getEnd(), &op_delta ).getStart(); if (!count) { // The first flowplan in the list will always be there, even when the quantity becomes 0. // It is responsible for creating extra flowplans when required. while (totalcount < batches) { auto newflowplan = new FlowPlan(fl->getOperationPlan(), this); newflowplan->setFollowingBatch(true); ++totalcount; } } if (getQuantity() > 0 || getQuantityFixed() > 0) { // Producing a batch op_delta = static_cast<long>(op_delta) / static_cast<long>(batches) * (count + 1); total_quantity -= count * batch_quantity; if (total_quantity < 0.0) total_quantity = 0.0; return make_pair( fl->getOperation()->calculateOperationTime( fl->getOperationPlan(), op_date, op_delta, true ).getEnd(), total_quantity > batch_quantity ? batch_quantity : total_quantity ); } else { // Consuming a batch op_delta = static_cast<long>(op_delta) / static_cast<long>(batches) * count; total_quantity += count * getTransferBatch(); if (total_quantity > 0.0) total_quantity = 0.0; return make_pair( fl->getOperation()->calculateOperationTime( fl->getOperationPlan(), op_date, op_delta, true ).getEnd(), total_quantity < -batch_quantity ? -batch_quantity : total_quantity ); } }
Quantity FFactorGroundFloorConstruction_Impl::getFFactor(bool returnIP) const { OSOptionalQuantity value = getQuantity(OS_Construction_FfactorGroundFloorFields::FFactor,true,returnIP); OS_ASSERT(value.isSet()); return value.get(); }
void Banker::run() { try { std::string ip = "127.0.0.1"; std::string port = "8080"; boost::asio::io_service io_service; tcp::socket s(io_service); tcp::resolver resolver(io_service); boost::asio::connect(s, resolver.resolve({ip.c_str(), port.c_str()})); for (;;) { // Wait sleep(1); // Get current cotation and quantity for stocks std::vector<int> current_price; current_price.resize(5); current_price[0] = getCotation("TC", &s); current_price[1] = getCotation("TI", &s); current_price[2] = getCotation("MM", &s); current_price[3] = getCotation("TE", &s); current_price[4] = getCotation("BI", &s); std::vector<int> current_qty; current_qty.resize(5); current_qty[0] = getQuantity("TC", &s); current_qty[1] = getQuantity("TI", &s); current_qty[2] = getQuantity("MM", &s); current_qty[3] = getQuantity("TE", &s); current_qty[4] = getQuantity("BI", &s); std::vector<int> cpy_actions = actions_own; // Get min/max of own actions int min_quantity = min(cpy_actions); int max_quantity = max(cpy_actions); // Get min/max price int min_price = min(current_price); int max_price = max(current_price); int old_wallet = wallet; if (objectif == BUY) { happy += 7; crazy += 1; std::string id = cpy[min_price]; if (current_price[min_price] == 0) current_price[min_price] = 1; int qty = wallet / current_price[min_price]; if (qty > current_qty[min_price]) { happy -= 2; qty = current_qty[min_price]; } std::string res = buy(id, qty, &s); if (res.compare("ok")) { wallet += qty * current_price[min_price]; actions_own[min_price] -= qty; } else happy -= 5; } else if (objectif == SELL) { happy += 10; crazy += 1; int i; std::string id; int qty = 0; if (actions_own[max_price] > 5) i = max_price; else i = max_quantity; id = cpy[i]; qty = actions_own[i]; sell(id, qty, &s); wallet += qty * current_price[i]; actions_own[i] -= qty; } else if (objectif == STOCK) { std::string id = cpy[max_quantity]; int qty = wallet / current_price[max_quantity]; sell(id, qty, &s); wallet += qty * current_price[max_quantity]; actions_own[max_quantity] -= qty; happy -= 5; crazy += 1; } else if (objectif == STANDBY) { happy -= 5; crazy += 5; } else if (objectif == RANDOM) { happy += 1; crazy += 10; if (rand() % 2 == 1) { int r = rand() % 6; std::string id = cpy[r]; int qty = rand() % actions_own[r]; std::string res = buy(id, qty, &s); if (res.compare("ok")) { wallet += qty * current_price[r]; actions_own[r] -= qty; } else happy -= 5; } else { int r = rand() % 6; std::string id = cpy[r]; int qty = rand() % actions_own[r]; sell(id, qty, &s); wallet += qty * current_price[r]; actions_own[r] -= qty; } } if (old_wallet < wallet) happy += 5; if (happy == 0) { status = SAD; objectif = STANDBY; happy = rand() % 100 == 50 ? 50 : 0; crazy = 0; } else if (crazy == 0) { status = SAD; objectif = STOCK; crazy += rand() % 2 == 1 ? 10 : 0; } if (happy > crazy) { status = HAPPY; objectif = (rand() % 2 == 0) ? BUY : SELL; crazy = (happy == 4 * crazy) ? 4 * crazy : crazy; } else if (crazy > happy) { status = CRAZY; objectif = RANDOM; crazy -= rand() % 4 == 2 ? 2 : 1; } std::string filename = std::string("src/market/market_site/agent") + name + std::string(".info"); std::ofstream log(filename); log << "> Agent status = " << getStatus() << std::endl; log << "> Agent objectif = " << getObjectif() << std::endl; log << "> Currents actions quantity:" << std::endl; log << " > TC = " << actions_own[0] << std::endl; log << " > TI = " << actions_own[1] << std::endl; log << " > MM = " << actions_own[2] << std::endl; log << " > TE = " << actions_own[3] << std::endl; log << " > BI = " << actions_own[4] << std::endl; log << "> Wallet = " << wallet << "$" <<std::endl; log.close(); } } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; } }
Quantity ConstructionWithInternalSource_Impl::getTubeSpacing(bool returnIP) const { OSOptionalQuantity value = getQuantity(OS_Construction_InternalSourceFields::TubeSpacing,true,returnIP); OS_ASSERT(value.isSet()); return value.get(); }
bool CItemShop::IsInMenu() { return getQuantity() != 0; }
void Consumable::dumpObjectData() { Item::dumpObjectData(); cout<<" quantity : "<< getQuantity() <<endl; }
void Consumable::writeDataAsFragment(ostream & output) { Item::writeDataAsFragment(output); output<< " <quantity>"<<getQuantity()<<"</quantity>"<<endl; }
bool FFactorGroundFloorConstruction_Impl::setPerimeterExposed(double perimeterExposed) { OSOptionalQuantity temp = getQuantity(OS_Construction_FfactorGroundFloorFields::PerimeterExposed,true,false); bool result = setPerimeterExposed(Quantity(perimeterExposed,temp.units())); return result; }