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
|
using namespace std;
//using namespace System;
// array::begin example
#include <iostream>
#include <fstream>
#include <array>
#include <vector>
class arc
{
// const int M=1000000;
public:
arc(int Id=0, int co=1000000, int tr=1000000) : ID(Id), cost(co), transit_time(tr) {}
int ID; // The tail(nodes) or head(B) of arc.
int cost;
int transit_time;
};
class label
{ public:
const int M=1000000;
label(int pe=1000000, int tem=1000000, int pre=0): permanent(pe), temp(tem), pred(pre){}
int permanent;
int temp;
int pred;
};
class Network{
public:
Network(int nn=1000000, int ss=1, int tt=1000000, int TT=1000000): n(nn), s(ss), t(tt), T(TT){}
const int M=1000000;
const int NumberofNodes=2000;
std::array<std:: vector<arc>,NumberofNodes+1> nodes; //adjacency List
std::array<label,NumberofNodes+1> Distance_Label; //To trace Shortest Path
int n; //number of nodes.
int s; //source
int t; // sink
int T; //time horizon
void nodes_initials();
void create_Network();
void add_arc_nodes(int , arc );
void print_shortest_path();
};
void Network::nodes_initials(){
// std::cout << "Please enter the number of nodes:"<< std::endl;
// std::cin >> n;
std::cout << "Please enter the ID of source:"<<endl;
std::cin >> s;
std::cout << "Please enter the ID of sink:"<<endl;
std::cin >> t;
std::cout << "Please enter the time horizon:"<<endl;
std::cin >> T;
}
void Network::add_arc_nodes(int i, arc a) // i is the head of arc a.
{
nodes[i].push_back(a);
}
void Network::create_Network() // read the network's parameter from data file.
{
int i;//head of arc.
int j;//tail of arc.
int co;// cost of arc.
int tr; //transit time of arc.
ifstream file;
file.open("Data.txt", ios::in);
while(file >> i >> j >> co >> tr)
{
arc a(j, co, tr);
add_arc_nodes(i,a);
}
file.close();
}
int main()
{ Network x;
int i;
x.nodes_initials();
x.create_Network();
std::cout<<i;
std::cin>>i;
return 0;
}
| |