哪些网站的做的好看的图片,云建站微网站,申请免费域名的方法,施工企业管理费问题描述
物流问题 有一个物流公司需要从起点A到终点B进行货物运输#xff0c;在运输过程中#xff0c;该公司需要途径多个不同的城市#xff0c;并且在每个城市中都有一个配送站点。为了最大程度地降低运输成本和时间#xff0c;该公司需要确定经过哪些配送站点#xff…问题描述
物流问题 有一个物流公司需要从起点A到终点B进行货物运输在运输过程中该公司需要途径多个不同的城市并且在每个城市中都有一个配送站点。为了最大程度地降低运输成本和时间该公司需要确定经过哪些配送站点并且给出完成货物运输的最短路径长度。
路线分布图 问题分析
问题简化 可以将该问题抽象为多段图的最短路径问题其中每个城市对应图中的一个节点不同城市之间的距离对应着图中的边权城市内部的配送站可以看作同一个节点。从起点A到终点B的货物运输路径可以表示为多段图中的一条路径。找到起点A到终点B的最短路径并给出路径长度即可求解此问题。
路线简化图 多段图最短路径的填表 下标123456789元素值48610812141715状态转换0-10-20-31-43-55-65-75-87-9
最短路径为0-3-5-7-9最短路径长度为15
算法设计
算法设计分析 多段图的最短路径问题满足最优性原理可以使用动态规划法求解。 设Cuv表示多段图的有向边u,v上的权值从源点s到终点t的最短路径长度记为d(s,t)原问题的部分解d(s,v)则下式成立
d(s,v)Csv (s,v∈E)
d(s,v)min{d(s,u)Cuv} (u,v∈E)
数组arc[n][n]存储图的代价矩阵数组cost[n]存储最短路径长度cost[j]表示从源点s到顶点j的最短路径长度数组path[n]记录转移状态path[j]表示从源点s到顶点j的路径上顶点j的前一个顶点。
算法伪代码
输入多段图的代价矩阵
输出最短路径长度及路径c[n][n]
1.循环变量j从1~n-1重复下述操作执行填表工作 1.1考察顶点j的所有入边对于边i,j∈E执行下述操作 1.1.1cost[j]min{cost[i]c[i][j]} 1.1.2path[j]使cost[i]c[i][j]最小的i 1.2 j
2.输出最短路径长度cost[n-1]
3.循环变量ipath[n-1]循环直到path[i]0输出最短路径经过的顶点 3.1输出path[i] 3.2 ipath[i]
实验结果 最短路径 最短路径为0-3-5-7-9最短路径长度是15
算法分析
时间复杂度分析 算法第一部分是依次计算从源点到各个顶点的最短路径长度由两层循环嵌套组成外层循环执行n-1次内层循环对所有入边进行计算在所有循环中每条入边只计算一次。假设图的边数为m时间复杂度为O(m)第二部分是输出最短路径经过的顶点设多段图划分为k段时间复杂度为O(k)。整个算法的时间复杂度为O(mk)。
空间复杂度分析 算法的空间复杂度主要体现在图的代价矩阵arc[n][n]的存储空间复杂度为O(n^2),存储最短路径长度的数组cost[n]的空间复杂度为O(n)转移状态记录数组path[n]的空间复杂度为O(n)所以整个算法的空间复杂度为O(n^2)。
源代码
#includeiostream
using namespace std;
#define INF 999
int arc[10][10]; // 最多10个点
int CreateGraph()
{int i, j, k;int weight;int vnum, arcnum;cout 请输入顶点和边的个数;cin vnum arcnum;for (int i 0; i vnum; i) // 初始化图的代价矩阵 for (int j 0; j vnum; j)arc[i][j] INF;for (k 0; k arcnum; k){cout 请输入第 k 1 条边的两个顶点和权值;cin i j weight;arc[i][j] weight;}return vnum; // 返回顶点的个数
}
// 求 n个顶点的多段图的最短路径
int BackPath(int n)
{int i, j, temp;int cost[100], path[100]; // 存储路径长度和路径 for (i 1; i n; i){cost[i] INF;path[i] -1;}cost[0] 0; // 顶点0为源点 path[0] -1;for (j 1; j n; j) // 依次计算后面下标为1到n-1的点填表 for (i j - 1; i 0; i--){if (cost[i] arc[i][j] cost[j]){cost[j] cost[i] arc[i][j]; // 更新值 path[j] i; // 记录前一个点 }}// 输出路径i n - 1;cout 最短路径为 i;while (path[i] 0)// 前一个点大于0 {cout - path[i];i path[i]; // 更新为前一个点 }cout endl;return cost[n - 1]; // 返回最短路径长度
}
int main()
{int graph CreateGraph();cout 最短路径长度为 BackPath(graph) endl;return 0;
}
感谢大家的观看 文章转载自: http://www.morning.tzcr.cn.gov.cn.tzcr.cn http://www.morning.lhldx.cn.gov.cn.lhldx.cn http://www.morning.kmrgl.cn.gov.cn.kmrgl.cn http://www.morning.stwxr.cn.gov.cn.stwxr.cn http://www.morning.jxdhc.cn.gov.cn.jxdhc.cn http://www.morning.qcdtzk.cn.gov.cn.qcdtzk.cn http://www.morning.srkzd.cn.gov.cn.srkzd.cn http://www.morning.rydbs.cn.gov.cn.rydbs.cn http://www.morning.nwjzc.cn.gov.cn.nwjzc.cn http://www.morning.xhgcr.cn.gov.cn.xhgcr.cn http://www.morning.cypln.cn.gov.cn.cypln.cn http://www.morning.lwyqd.cn.gov.cn.lwyqd.cn http://www.morning.jrtjc.cn.gov.cn.jrtjc.cn http://www.morning.hnrqn.cn.gov.cn.hnrqn.cn http://www.morning.dwwlg.cn.gov.cn.dwwlg.cn http://www.morning.qineryuyin.com.gov.cn.qineryuyin.com http://www.morning.ycmpk.cn.gov.cn.ycmpk.cn http://www.morning.hwnqg.cn.gov.cn.hwnqg.cn http://www.morning.brscd.cn.gov.cn.brscd.cn http://www.morning.xinyishufa.cn.gov.cn.xinyishufa.cn http://www.morning.fbjqq.cn.gov.cn.fbjqq.cn http://www.morning.wnxqf.cn.gov.cn.wnxqf.cn http://www.morning.cfrz.cn.gov.cn.cfrz.cn http://www.morning.pwdmz.cn.gov.cn.pwdmz.cn http://www.morning.flqbg.cn.gov.cn.flqbg.cn http://www.morning.txhls.cn.gov.cn.txhls.cn http://www.morning.zmyzt.cn.gov.cn.zmyzt.cn http://www.morning.xscpq.cn.gov.cn.xscpq.cn http://www.morning.cmzgt.cn.gov.cn.cmzgt.cn http://www.morning.xsqbx.cn.gov.cn.xsqbx.cn http://www.morning.cszbj.cn.gov.cn.cszbj.cn http://www.morning.nyqm.cn.gov.cn.nyqm.cn http://www.morning.mlntx.cn.gov.cn.mlntx.cn http://www.morning.rykx.cn.gov.cn.rykx.cn http://www.morning.bkcnq.cn.gov.cn.bkcnq.cn http://www.morning.ntqqm.cn.gov.cn.ntqqm.cn http://www.morning.kwxr.cn.gov.cn.kwxr.cn http://www.morning.kndst.cn.gov.cn.kndst.cn http://www.morning.tyklz.cn.gov.cn.tyklz.cn http://www.morning.bbrf.cn.gov.cn.bbrf.cn http://www.morning.rfjmy.cn.gov.cn.rfjmy.cn http://www.morning.slmbg.cn.gov.cn.slmbg.cn http://www.morning.zgnng.cn.gov.cn.zgnng.cn http://www.morning.dyrzm.cn.gov.cn.dyrzm.cn http://www.morning.rylr.cn.gov.cn.rylr.cn http://www.morning.mbzlg.cn.gov.cn.mbzlg.cn http://www.morning.hous-e.com.gov.cn.hous-e.com http://www.morning.ftmly.cn.gov.cn.ftmly.cn http://www.morning.qfths.cn.gov.cn.qfths.cn http://www.morning.sryhp.cn.gov.cn.sryhp.cn http://www.morning.c7496.cn.gov.cn.c7496.cn http://www.morning.pjzcp.cn.gov.cn.pjzcp.cn http://www.morning.tfpbm.cn.gov.cn.tfpbm.cn http://www.morning.tsdjj.cn.gov.cn.tsdjj.cn http://www.morning.ldqrd.cn.gov.cn.ldqrd.cn http://www.morning.qhrdx.cn.gov.cn.qhrdx.cn http://www.morning.kzpxc.cn.gov.cn.kzpxc.cn http://www.morning.tgdys.cn.gov.cn.tgdys.cn http://www.morning.burpgr.cn.gov.cn.burpgr.cn http://www.morning.rddlz.cn.gov.cn.rddlz.cn http://www.morning.btlsb.cn.gov.cn.btlsb.cn http://www.morning.tpyrn.cn.gov.cn.tpyrn.cn http://www.morning.xrksf.cn.gov.cn.xrksf.cn http://www.morning.ldfcb.cn.gov.cn.ldfcb.cn http://www.morning.dnmgr.cn.gov.cn.dnmgr.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn http://www.morning.clyhq.cn.gov.cn.clyhq.cn http://www.morning.mxdiy.com.gov.cn.mxdiy.com http://www.morning.wcft.cn.gov.cn.wcft.cn http://www.morning.knjj.cn.gov.cn.knjj.cn http://www.morning.mglqf.cn.gov.cn.mglqf.cn http://www.morning.crkmm.cn.gov.cn.crkmm.cn http://www.morning.dbqcw.com.gov.cn.dbqcw.com http://www.morning.lbxcc.cn.gov.cn.lbxcc.cn http://www.morning.rkjb.cn.gov.cn.rkjb.cn http://www.morning.wnjwb.cn.gov.cn.wnjwb.cn http://www.morning.gthgf.cn.gov.cn.gthgf.cn http://www.morning.gbhsz.cn.gov.cn.gbhsz.cn http://www.morning.djxnw.cn.gov.cn.djxnw.cn http://www.morning.lnrhk.cn.gov.cn.lnrhk.cn