1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include<fstream>
#include <vector>
using namespace std;
int main()
{
vector<vector<double>>cost_temp;
vector<int> Period;
vector<int> First;
vector<double> D= { 20, 30, 40, 50, 60 };
vector<double>f = { 20, 30, 40, 10, 40 };
vector<double>h = { 2, 4 ,2 ,4, 2 };
vector<double>c = { 5, 10, 15, 6 ,10 };
Period = { 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4 };
First = { 0, 1, 3, 11, 13 };
vector<int>Opt_cost(14);
Opt_cost[0] = 0;
for (int i = 1; i < 14; i++)
{
for (int k = 0; k < First[Period[i]]; k++)
{
double sum = 0;
double P_sum = 0;
for (int kk = Period[k]; kk < Period[i]; kk++)
sum += D[kk];
double h_sum = 0;
P_sum = c[Period[k]] * sum;
for (int kk = Period[k]; kk < Period[i]; kk++)
{
h_sum = h_sum + h[kk] * (sum - D[kk]);
sum = sum - D[kk];
}
// cost_temp[i][k] = h_sum + P_sum + f[Period[k]];
cout << "cost="<< Opt_cost[k] + h_sum + P_sum + f[Period[k]]<< endl;
}
}
return 0;
}
| |