Hi everyone, I got a task to insert a value (1 or 2) into each row. But, the chosen value is based on the minimum distance from the previous number.
And the position in the row where the new value are inserted are based on this two condition:
1. total capacity (currentQ) must less or equal to Q (then, insert 1 or 2)
2. total capacity (totalQ) must less or equal to maxQ (then, insert 1 or 2, after that insert 0)
Q is the vehicle capacity. While, maxQ is the max vehicle capacity per day.
We need to reset currentQ = 0 whenever the load is less than or equal to Q after inserting new value.
Hopefully, you will understand what i'm trying to explain.
For example, route row 0:
0 3 6 9 7 5 0
should be:
0 3 6 1 9 7 2 0 5 1 0
Here is the route data:
0 3 6 9 7 5 0
0 4 12 8 10 3 0
0 12 11 6 4 7 0
Distance data:
0 2.914204545 58.55435606 2.877083333 2.281439394 3.704166667 3.063068182 1.719507576 1.094507576 2.274431818 32.92443182 32.76022727 18.33901515
2.914204545 0 56.12916667 5.791287879 5.195643939 6.618371212 5.977272727 4.633712121 4.008712121 4.699621212 30.01022727 29.84602273 15.42481061
58.55435606 56.12916667 0 58.2094697 56.56685606 59.83579545 60.83219697 59.09280303 59.57954545 60.82878788 28.59431818 28.09753788 44.46117424
2.877083333 5.791287879 58.2094697 0 1.642613636 1.626325758 2.622727273 1.157575758 1.782575758 3.045075758 35.80151515 35.63731061 21.21609848
2.281439394 5.195643939 56.56685606 1.642613636 0 3.268939394 4.265340909 2.52594697 3.012689394 4.261931818 35.20587121 35.04166667 20.62045455
3.704166667 6.618371212 59.83579545 1.626325758 3.268939394 0 0.996401515 1.984659091 2.609659091 3.872159091 36.62859848 36.46439394 22.04318182
3.063068182 5.977272727 60.83219697 2.622727273 4.265340909 0.996401515 0 1.739393939 1.968560606 3.231060606 35.9875 35.82329545 21.40208333
1.719507576 59.09280303 4.633712121 1.157575758 2.52594697 1.984659091 1.739393939 0 0.625 1.8875 34.64393939 34.47973485 20.05852273
1.094507576 59.57954545 4.008712121 1.782575758 3.012689394 2.609659091 1.968560606 0.625 0 1.2625 34.01893939 33.85473485 19.43352273
2.274431818 4.699621212 60.82878788 3.045075758 4.261931818 3.872159091 3.231060606 1.8875 1.2625 0 32.75643939 32.73125 18.17102273
32.92443182 28.59431818 30.01022727 35.80151515 35.20587121 36.62859848 35.9875 34.64393939 34.01893939 32.75643939 0 0.496780303 15.86685606
32.76022727 28.09753788 29.84602273 35.63731061 35.04166667 36.46439394 35.82329545 34.47973485 33.85473485 32.73125 0.496780303 0 16.36363636
18.33901515 15.42481061 44.46117424 21.21609848 20.62045455 22.04318182 21.40208333 20.05852273 19.43352273 18.17102273 15.86685606 16.36363636 0
Load/capacity data:
0 0
1 0
2 0
3 14
4 17
5 16
6 15
7 18
8 20
9 26
10 30
11 33
12 12
I had try do the the coded but it seem wrong somewhere and the error also occurred. I don't know how to solve it. Hope anyone can help me.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <iostream>
#include <vector>
#include <iomanip> // setw
#include <fstream>
using namespace std;
const int routeRow = 3; // Route row / population size
const int routeCol = 7; // Route column
const int m = 13; // Number of nodes / stop
const int dataCol = 2; // Data column
long double Q = 50.0; // Vehicle capacity
long double maxQ = 80.0; // Max vehicle capacity per day
vector<vector<long double> > data(m, vector <long double>(dataCol, 0));
vector<vector<int> > route(routeRow, vector <int>(routeCol, 0));
vector<vector<long double> > dist(m, vector <long double>(m, 0));
vector<long double> load(m);
int i, j;
int main()
{
// Input file
ifstream inpData("myData.txt");
ifstream inpRoute("myRoute.txt");
ifstream inpDistance("myDistance.txt");
// Assign data into array
cout << "The load data are: ";
cout << endl;
for (i = 0; i < m; i++)
{
for (j = 0; j < dataCol; j++)
{
inpData >> data[i][j];
cout << setw(3) << data[i][j] << ' ';
}
cout << endl;
}
cout << endl;
// Assign route into array
cout << "The routes are: ";
cout << endl;
for (i = 0; i < routeRow; i++)
{
for (j = 0; j < routeCol; j++)
{
inpRoute >> route[i][j];
cout << setw(3) << route[i][j] << ' ';
}
cout << endl;
}
cout << endl;
// Assign distance into array
cout << "The distances are: ";
cout << endl;
for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
{
inpDistance >> dist[i][j];
cout << setw(10) << dist[i][j] << ' ';
}
cout << endl;
}
cout << endl;
// Assign load into array
for (i = 0; i < m; i++)
{
load[i] = data[i][1];
}
// Close input files
inpData.close();
inpRoute.close();
inpDistance.close();
for(i = 0; i < routeRow; i++)
{
double currentQ = 0;
double totalQ = 0;
for(j = 0; j < routeCol; j++)
{
if ((currentQ + load[route[i][j]] <= Q)
&& (totalQ + load[route[i][j]] <= maxQ))
{
// Inserts '1' or '2' (choose minimum distance from previous number)
// when currentQ less or equal to Q and totalQ less or equal to maxQ).
vector<int>::iterator it = route[i].insert(route[i].begin(), route[i].end(), 1);
}
}
}
cout << endl;
// Displaying solution
for (int i = 0; i < routeRow; i++)
{
for (int j = 0; j < route[i].size(); j++)
{
cout << setw(3) << route[i][j] << ' ';
}
cout << endl;
}
cout << endl;
system("pause");
return 0;
}
|