Beispiel #1
0
void Client::approveIngredients( std::map<Dish*,ApprovedItem>* temp, Cafe_Menu* menu)
{
	auto dishes = menu->getMenu();
	int index = -1;
	std::vector<Dish*> indexes;
	for(auto it = temp->begin(); it != temp->end();++it)
	{
		index++;
		Dish* tempDish = static_cast<Dish*>(it->first);
		std::vector<std::tuple<IngredientKinds,bool>> tempList = it->second.ApproveIgredients;
		bool isApprove = (rand() % 100) > 50 ? true : false;
		if(isApprove)
		{
			printf_s("Client %s  has approved changes for %s\n",getFullName().c_str(),tempDish->getName().c_str());
			for(size_t i = 0; i < tempList.size();i++)
			{
				auto tempTuple = tempList.at(i);
				std::get<1>(tempTuple) = true;
			}
		}
		else
		{
			size_t index = rand() % dishes.size();
			if(index > dishes.size())
				continue;
			Dish* dish = new Dish(*dishes.at(index));
			it->second.AlternativeDish = dish;
			it->second.ApproveIgredients.clear();
			printf_s("Client %s  hasn't approved changes for %s\n",getFullName().c_str(),tempDish->getName().c_str());
			printf_s("Client %s  has chosen new dish %s\n",getFullName().c_str(),dish->getName().c_str());
			
		}
	}
}
Beispiel #2
0
int main(int argc, char **argv){
	DBR reasoner = DBR(argv[1],argv[2]);
	int choice = 0;
	Case prob = Case();
	Dish sol = Dish();
	while((choice = mainMenu()) != 3){
		switch(choice){
			case 1:
				reasoner.addDish(constructDish());
				break;
			case 2:
				prob = constructProblem();
				sol = reasoner.query(prob);
				cout << "You should try ";
				cout << sol.getName() <<endl;
				if(goodSuggestion()){
					reasoner.addCase(Case(prob.getLikes(), prob.getDislikes(), sol));
				}
				break;
			default:
				cout << "Unrecognized input!" <<endl;
				break;
		}
	}
	cout << "Bye!" <<endl;
	reasoner.save(argv[1],argv[2]);
	return 0;
}
Beispiel #3
0
Dish* Ingridients::readDish(const QJsonObject& json) {
    PRINT_DEBUG("Reading new dish");

    QJsonArray itemsList = json["items"].toArray();
    Food* newFood = readFood(itemsList[0].toObject()["food"].toObject());
    Dish* newDish = new Dish(json["name"].toString().toStdString(), newFood,
                             itemsList[0].toObject()["amount"].toInt());

    avaliableItems.push_back(newFood);
    newFood->addItemList(&avaliableItems);

    for ( int index = 1; index < itemsList.size(); index++ ) {
        newFood = readFood(itemsList[index].toObject()["food"].toObject());
        newDish->addFood(newFood, itemsList[index].toObject()["amount"].toInt());
        std::list<Item*>::iterator it;

        for ( it = avaliableItems.begin(); ; it++ ) {
            if ( !(*it)->getName().compare(newFood->getName()) ) {
                delete newFood;

                break;
            } else if ( it == avaliableItems.end() ) {
                avaliableItems.push_back(newFood);
                newFood->addItemList(&avaliableItems);
            }
        }
    }

    return newDish;
}
Beispiel #4
0
void Ingridients::loadDish(const QJsonArray& jsonArray) {
    PRINT_DEBUG("Loading dish");

    for ( int i = 0; i < jsonArray.size(); i++ ) {
        Dish* newDish = readDish(jsonArray[i].toObject());
        std::list<Dish*>::iterator it = std::find(avaliableDish.begin(), avaliableDish.end(), newDish);

        if ( it == avaliableDish.end() ) {
            avaliableDish.push_back(newDish);
            newDish->addDishList(&avaliableDish);
        }
    }
}
Beispiel #5
0
Dish* Dish::create(const std::string& anImageFileName, const std::vector<int>& anIngridientIDsList)
{
    Dish *pRet = new Dish();
    if (pRet && pRet->init(anImageFileName, anIngridientIDsList))
    {
        //pRet->autorelease();
        return pRet;
    }
    else
    {
        delete pRet;
        pRet = NULL;
        return NULL;
    }

}
Beispiel #6
0
void Ingridients::writeDish(QJsonObject& json, Dish& dish) const {
    QJsonArray itemsList;

    PRINT_DEBUG("Writing dish" << dish.getName());

    json["name"] = QString::fromStdString(dish.getName());
    json["amountOfPeople"] = static_cast<qint64>(dish.getAmountOfPeople());

    for ( auto& entry: dish.getIngridientMap() ) {
        QJsonObject mapEntry;
        QJsonObject food;

        writeFood(food, *(entry.first));

        mapEntry["food"] = food;
        mapEntry["amount"] = static_cast<qint64>(entry.second);

        itemsList.append(mapEntry);
    }

    json["items"] = itemsList;
}