Giter VIP home page Giter VIP logo

operationalresearchapp's People

Contributors

treborsky avatar

Stargazers

 avatar

Watchers

 avatar

operationalresearchapp's Issues

Updating elements of a std::vector that is a public member of a class

In the snipper below, I encountered a problem, where I can't update the std::vector element or add new ones. I don't think it's because of the new C++20. The compiler error is as follows:
__ function 'operator[]' which returns const-qualified type 'std::vector::const_reference' (aka 'const Ingredient &') declared here __
__ candidate function template not viable: 'this' argument has type 'const std::vector', but method is not marked const __

double Solution::calculateMshop() const {
double Mshop = 0.0;
for(std::size_t j = 0; j < selectedRecipes.size(); ++j) {
// determine if we have all ingredients for the recipe
// if we don't have enough amount of an ingredient, then we buy one (we add the cost and increase
// the ingredient amount)
if (selectedRecipes[j]) { // we select availableRecipies[i]
for(std::size_t i = 0; i < appData.availableRecipies[i].ingredientList.size(); ++i) {
// search through the ingredient list and determine if we have enough of the ingredient
Ingredient currentRecipeIngredient = appData.availableRecipies[j].ingredientList[i];
std::size_t idxIfWeHaveIt = -1;
bool isEnough = false;
for(std::size_t k = 0; k < appData.storedIngredients.size(); ++k) {
if (appData.storedIngredients[k].name == currentRecipeIngredient.name) { // do we have it on the list
idxIfWeHaveIt = k;
if (appData.storedIngredients[k].amount >= currentRecipeIngredient.amount) { // do we have enough of the thing
isEnough = true; // we have enough of the thing do make the recipe
break;
}
break;
}
}
if (!isEnough) { // then we have to buy it
for(std::size_t k = 0; k < appData.shopSupplies.size(); ++k) { // we want to find a supply with the same name
if (appData.shopSupplies[k].name == currentRecipeIngredient.name) { // if we found it, we buy it
Mshop += (double)appData.shopSupplies[k].price; // we buy it
// TODO: include the Money variable from the mathematical model, right now we have
// basically infinite resources
if (idxIfWeHaveIt != -1) {
appData.storedIngredients[idxIfWeHaveIt].amount += appData.shopSupplies[k].amount; // TODO: fix this stuff
// because of C++20, we have to rewrite the entire vector of ingredients to update one element -> wtf
int expDate = appData.storedIngredients[idxIfWeHaveIt].expirationDate;
int amount = appData.storedIngredients[idxIfWeHaveIt].amount;
std::string name = appData.storedIngredients[idxIfWeHaveIt].name;
Ingredient updatedIngredient(expDate, amount + appData.shopSupplies[k].amount, name);
std::vector<Ingredient> newStoredIngredients;
newStoredIngredients.reserve(appData.storedIngredients.size());
for(std::size_t l = 0; l < appData.storedIngredients.size(); ++l) {
if (l != idxIfWeHaveIt) {
newStoredIngredients.push_back(appData.storedIngredients[l]);
} else {
newStoredIngredients.push_back(updatedIngredient);
}
} // we bought it goddamit, we also updated the vector
} else { // if we didn't have it in the first place
int expDate = appData.storedIngredients[k].expirationDate;
int amount = appData.storedIngredients[k].amount;
std::string name = appData.storedIngredients[k].name;
appData.storedIngredients.emplace_back(Ingredient(expDate, amount, name));
}
break;
}
}
}
}
}
}
return 0.0;
}

Multiplatform file parsing

nlohmann's json parser seems to work only on unix systems (Ubuntu 18.04 tested). We need windows compatibility, so we need to implement some sort of conversion that gets this done. We can do it in two ways:

  1. Algorythm (function)
    Input: windows formatted or linux formatted .json file
    Output: linux formatted .json file
    This is a bad idea, because the linux binary won't get a windows file

  2. Preprocessor logic
    If we add proper logic to our code, it will compile different parser versions for linux and windows builds.
    I think it's the better idea tbh.

Implement data structures and model

We need a model that we can optimize, so that's what we should implement at first. I propose we create a library we can link to, which will contain all data structures and logic of the mathematical model.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.