Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <cmath>
- struct CompanyBalance
- {
- CompanyBalance(double money, double goods)
- {
- money_ = money;
- goods_ = goods;
- }
- double money_;
- double goods_;
- };
- struct Random
- {
- int a_;
- int b_;
- Random()
- {
- srand(time(0));
- a_ = 1;
- b_ = 10;
- }
- int randomNumber()
- {
- return(a_ + rand() % b_);
- }
- int randomNumber(int a, int b)
- {
- return(a + rand() % b);
- }
- };
- struct Demand
- {
- int demandCount_;
- int checkDemand(Random rndm)
- {
- demandCount_ = 0;
- for (int i = 1; i < 5; i++)
- {
- int a = 0;
- if ((i == 1) || (i == 4))
- {
- a = rndm.randomNumber(1, 6);
- }
- else
- {
- a = rndm.randomNumber(1, 3);
- }
- if (a == 1)
- {
- demandCount_ += i;
- }
- }
- return(demandCount_);
- }
- };
- struct ProductOrder
- {
- double waitOrderTime_;
- int orderQty_;
- bool waitOrder_;
- ProductOrder()
- {
- waitOrder_ = false;
- waitOrderTime_ = 0;
- orderQty_ = 0;
- }
- void order(CompanyBalance &cb, Random rndm)
- {
- if (orderQty_ > 0)
- {
- cb.money_ -= 32 + (3 * orderQty_);
- waitOrderTime_ = rndm.randomNumber(3, 5)*0.1;
- }
- else
- {
- waitOrderTime_ = 0;
- }
- }
- int order(int qty)
- {
- orderQty_ = qty;
- if (orderQty_ > 0)
- {
- int money =( 32 + (3 * orderQty_));
- return(money);
- }
- }
- };
- struct OrderStrategy
- {
- int minProductQty_;//s
- int mountProductQty_;//I
- int lastProductQty_;//S
- OrderStrategy(int minproduct)
- {
- minProductQty_ = minproduct;
- }
- int checkOrder(CompanyBalance &cb,int lastQty)
- {
- if (cb.goods_ < minProductQty_)
- {
- lastProductQty_ = lastQty;
- int order = lastProductQty_ -cb.goods_;
- return(order);
- }
- else
- {
- return(0);
- }
- }
- };
- struct mounthTimer
- {
- double mounth_;
- double lastTimeDef_;
- mounthTimer()
- {
- mounth_ = 0;
- lastTimeDef_ = 0;
- }
- double getTime()
- {
- double inta;
- double time;
- time = modf(mounth_,&inta);
- return (time);
- }
- void upTime(Random rndm)
- {
- lastTimeDef_= rndm.randomNumber(5, 11) * 0.01;//random 0.05-0.15 month;
- mounth_ += lastTimeDef_;
- }
- };
- struct ProductHold
- {
- int moneyHold_;
- int lastMoneyHold_;
- int ordercount_;
- ProductHold()
- {
- moneyHold_ = 0;
- lastMoneyHold_ = 0;
- ordercount_ =0;
- }
- void newMouth()
- {
- moneyHold_ = 0;
- lastMoneyHold_ = 0;
- ordercount_ = 0;
- }
- void producthold(CompanyBalance cb, int mh)
- {
- int buff=cb.goods_ - mh;
- if (buff >= 0)
- {
- lastMoneyHold_ = buff;
- }
- else
- {
- lastMoneyHold_ = buff * -5;
- }
- ordercount_++;
- moneyHold_ += lastMoneyHold_;
- }
- double monthHoldResult(bool a)
- {
- double result;
- if (a)
- {
- result = (moneyHold_-lastMoneyHold_)/(ordercount_-1);
- }else
- {
- result = (moneyHold_) / ordercount_;
- }
- return(result);
- }
- };
- int main()
- {
- double mounth =0;
- std::cout << "write month:";
- std::cin >> mounth;
- double mounthN = 1;
- mounthN +=mounth;
- std::cout << "\n";
- int checkMouth = 0;
- int summDef = 0;
- int holdsumm = 0;
- ProductHold ph;
- mounthTimer timer;
- OrderStrategy os(50);
- ProductOrder po;
- Random rm;
- Demand dm;
- CompanyBalance cb(100, 10);
- while (timer.mounth_ <= mounthN)
- {
- if (timer.mounth_ >= checkMouth)
- {
- if (timer.getTime() != 0)
- {
- if (timer.mounth_)
- {
- po.orderQty_ = os.checkOrder(cb, summDef - dm.demandCount_);
- po.order(cb, rm);
- po.waitOrder_ = true;
- cb.money_-=ph.monthHoldResult(timer.getTime() != 0);
- int moun = timer.mounth_;
- int res = ph.monthHoldResult(timer.getTime() != 0);
- std::cout << "\n" << "mounth:" << moun << "\n";
- std::cout << "costs storage=" << res <<" costs buy="<< po.order(summDef - dm.demandCount_) << " demand=" << summDef - dm.demandCount_ << " goods=" << cb.goods_ << std::endl;
- }
- }
- else
- {
- if (timer.mounth_)
- {
- po.orderQty_ = os.checkOrder(cb, summDef);
- po.order(cb, rm);
- po.waitOrder_ = true;
- cb.money_ -= ph.monthHoldResult(timer.getTime() != 0);
- int moun = timer.mounth_;
- int res = ph.monthHoldResult(timer.getTime() != 0);
- std::cout << "\n" << "mounth:" << moun << "\n";
- std::cout << "costs storage=" << res << "costs buy=" << po.order(summDef - dm.demandCount_) << "costs buy=" << "demand=" << summDef - dm.demandCount_ << " goods=" << cb.goods_ << std::endl;
- }
- }
- //last month money def
- ph.newMouth();
- summDef = 0;
- checkMouth++;
- }
- if ((po.waitOrderTime_ <= timer.getTime())&&(po.waitOrder_))
- {
- cb.goods_ += po.orderQty_;
- po.waitOrder_ = false;
- }
- summDef += dm.checkDemand(rm);
- timer.upTime(rm);
- ph.producthold(cb,summDef);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement