#include#include #include#include #include #include #include using namespace std;struct vec_load{ int vnum; int rest; vec_load(int iint j):vnum(i)rest(j){} } ; class path { public: deque no; int dis; double vec; int fr; path(double vint i):vec(v)f(i)r(i){ } };void creatpath(int& numbint** distvector& loaddouble re); int main(){ int numb=14; double temp; cout<<“请输入客户数:“< ifstream fin(“dist.txt“); cin>>numb; cout<<“请依次输入各个客户需求量(用空格隔开):“< vector load;//用于存储各物流子节点货物量需求量 for(int i=0;i { cin>>temp; load.push_back(temp); } int **dist; //指向存储给节点最短距离的二维数组 dist=new int*[numb+1]; for(int i=0;i dist[i]=new int[numb+1]{0}; //cout<<“请依次输入各客户到配送中心的最短距离:“< for(int i=0;i { fin>>dist[0][i+1]; dist[i+1][0]=dist[0][i+1]; } for(int i=1;i { //cout<<“请输入“< for(int j=i+1;j<=numb;j++) { fin>>dist[i][j]; dist[j][i]=dist[i][j]; } } //循环获取配送中心的车辆载荷及对应数量,用vector进行存储 double re=15; // cout<<“请输入车辆载荷“< //cin>>re; creatpath(numbdistloadre); return 0; } void creatpath(int& numbint** distvector& loaddouble re) { //新建一个numb维表格存储节约里程 int**save; save=new int*[numb]; for(int i=0;i save[i]=new int[numb]{0}; //计算节约里程并填入save表中指定位置 for(int i=0;i { for(int j=i+1;j { save[i][j]=dist[0][i+1]+dist[0][j+1]-dist[i+1][j+1]; save[j][i]=save[i][j]; } } //定义一个类,存储两节的编号以及节约里程,便于后续排序 class Save_node { public: int mn; int dis; void set(int &iint &jint&d) { this->m=i; this->n=j; this->dis=d; } }; Save_node temp; vector rsave; for(int i=0;i for(int j=i+1;j { temp.set(ijsave[i][j]); rsave.push_back(temp); } sort(rsave.begin()rsave.end()[](Save_node& s1Save_node& s2){return s1.dis>s2.dis;}); auto it1=rsave.begin(); /* for(auto &r:rsave){ cout<<“\t“<}*/ vector result; int time=0; for(auto &v:load) { auto ptemp=path(vtime); ptemp.dis=2*dist[0][time+1]; ptemp.no.push_back(time); ptemp.f=ptemp.no.front(); ptemp.r=ptemp.no.back(); result.push_back(ptemp); time++; } vector suc; bool fnode(int& path &); bool rnode(int& path &); while(suc.size()!=numb&&it1!=rsave.end()) { int head=it1->m; int back=it1->n; //cout<m<<“\t“<n<<“\t“<dis< auto i1=
共有 条评论
评论
共有 条评论