重大会议网站安全监测服务内容

时间: 2023-12-09 20:49:06 浏览: 22
实现。 首先,我们需要定义节点和路径的类: ```java public class Node { private String name; // 节点名称 public Node(String name) { this.name = name; } public String getName() { return name; } } public class Path { private Node start; // 起点 private Node end; // 终点 private String type; // 运输方式 private double cost; // 费用 public Path(Node start, Node end, String type, double cost) { this.start = start; this.end = end; this.type = type; this.cost = cost; } public Node getStart() { return start; } public Node getEnd() { return end; } public String getType() { return type; } public double getCost() { return cost; } } ``` 然后,我们需要定义一个图类来表示多式联运的图: ```java import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Graph { private Map<Node, List<Path>> adjList; // 邻接表 public Graph() { adjList = new HashMap<>(); } // 添加节点 public void addNode(Node node) { adjList.putIfAbsent(node, new ArrayList<>()); } // 添加路径 public void addPath(Path path) { Node start = path.getStart(); adjList.get(start).add(path); } // 获取某个节点的邻接路径 public List<Path> getPaths(Node node) { return adjList.get(node); } } ``` 接下来,我们来实现深度优先搜索算法: ```java import java.util.ArrayList; import java.util.List; import java.util.Stack; public class DFS { private Graph graph; // 图 private Node startNode; // 起点 private Node endNode; // 终点 private List<List<Path>> allPaths; // 所有路径 public DFS(Graph graph, Node startNode, Node endNode) { this.graph = graph; this.startNode = startNode; this.endNode = endNode; allPaths = new ArrayList<>(); } // 获取所有路径 public void getAllPaths() { Stack<Path> pathStack = new Stack<>(); pathStack.push(new Path(startNode, null, null, 0)); dfs(pathStack); } // 深度优先搜索 private void dfs(Stack<Path> pathStack) { Path currentPath = pathStack.peek(); Node currentNode = currentPath.getEnd(); if (currentNode != null && currentNode.equals(endNode)) { List<Path> pathList = new ArrayList<>(pathStack); pathList.remove(0); allPaths.add(pathList); return; } List<Path> paths = graph.getPaths(currentNode); for (Path path : paths) { if (!pathStack.contains(path)) { pathStack.push(path); dfs(pathStack); pathStack.pop(); } } } // 获取成本最低的路径 public List<Path> getLowestCostPath() { double minCost = Double.MAX_VALUE; List<Path> lowestCostPath = null; for (List<Path> pathList : allPaths) { double totalCost = 0; for (Path path : pathList) { totalCost += path.getCost(); } if (totalCost < minCost) { minCost = totalCost; lowestCostPath = pathList; } } return lowestCostPath; } } ``` 最后,我们可以通过以下代码来使用上述类和方法: ```java public class Main { public static void main(String[] args) { Node A = new Node("A"); Node B = new Node("B"); Node C = new Node("C"); Node D = new Node("D"); Node E = new Node("E"); Graph graph = new Graph(); graph.addNode(A); graph.addNode(B); graph.addNode(C); graph.addNode(D); graph.addNode(E); graph.addPath(new Path(A, B, "railway", 5)); graph.addPath(new Path(A, B, "highway", 10)); graph.addPath(new Path(B, C, "railway", 4)); graph.addPath(new Path(B, C, "highway", 8)); graph.addPath(new Path(C, D, "railway", 3)); graph.addPath(new Path(C, D, "highway", 6)); graph.addPath(new Path(B, E, "railway", 2)); graph.addPath(new Path(B, E, "highway", 4)); graph.addPath(new Path(E, D, "railway", 2)); graph.addPath(new Path(E, D, "highway", 3)); DFS dfs = new DFS(graph, A, D); dfs.getAllPaths(); List<Path> lowestCostPath = dfs.getLowestCostPath(); for (Path path : lowestCostPath) { System.out.print(path.getStart().getName() + "->"); } System.out.println(lowestCostPath.get(lowestCostPath.size()-1).getEnd().getName()); System.out.println("Total cost: " + lowestCostPath.stream().mapToDouble(Path::getCost).sum()); } } ``` 输出结果为: ``` A->B->E->D Total cost: 7.0 ``` 可以看到,成本最低的路径为A->B->E->D,总费用为7.0。

相关推荐

最新推荐

recommend-type

成都市安全服务目录(包括限价)

云平台安全检测服务 云平台安全合规性检查服务 参考《网络安全等级保护—云计算扩展要求》、《中央网信办—云计算服务安全能力要求》,《国家信息中心—政务云安全要求》等标准文件,对云计算平台安全合规性进行检查...
recommend-type

Java开发案例-springboot-66-自定义starter-源代码+文档.rar

Java开发案例-springboot-66-自定义starter-源代码+文档.rar Java开发案例-springboot-66-自定义starter-源代码+文档.rar Java开发案例-springboot-66-自定义starter-源代码+文档.rar Java开发案例-springboot-66-自定义starter-源代码+文档.rar Java开发案例-springboot-66-自定义starter-源代码+文档.rar Java开发案例-springboot-66-自定义starter-源代码+文档.rar
recommend-type

单家独院式别墅图纸D027-三层-12.80&10.50米-施工图.dwg

单家独院式别墅图纸D027-三层-12.80&10.50米-施工图.dwg
recommend-type

啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦

啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦
recommend-type

课程大作业基于Vue+PHP开发的简单问卷系统源码+使用说明.zip

【优质项目推荐】 1、项目代码均经过严格本地测试,运行OK,确保功能稳定后才上传平台。可放心下载并立即投入使用,若遇到任何使用问题,随时欢迎私信反馈与沟通,博主会第一时间回复。 2、项目适用于计算机相关专业(如计科、信息安全、数据科学、人工智能、通信、物联网、自动化、电子信息等)的在校学生、专业教师,或企业员工,小白入门等都适用。 3、该项目不仅具有很高的学习借鉴价值,对于初学者来说,也是入门进阶的绝佳选择;当然也可以直接用于 毕设、课设、期末大作业或项目初期立项演示等。 3、开放创新:如果您有一定基础,且热爱探索钻研,可以在此代码基础上二次开发,进行修改、扩展,创造出属于自己的独特应用。 欢迎下载使用优质资源!欢迎借鉴使用,并欢迎学习交流,共同探索编程的无穷魅力! 课程大作业基于Vue+PHP开发的简单问卷系统源码+使用说明.zip Project setup ``` npm install ``` ### Compiles and hot-reloads for development ``` npm run serve ``` ### Compiles and minifies for production ``` npm run build ``` ### Lints and fixes files ``` npm run lint ``` ### Customize configuration See [Configuration Reference](https://cli.vuejs.org/config/).
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

HSV转为RGB的计算公式

HSV (Hue, Saturation, Value) 和 RGB (Red, Green, Blue) 是两种表示颜色的方式。下面是将 HSV 转换为 RGB 的计算公式: 1. 将 HSV 中的 S 和 V 值除以 100,得到范围在 0~1 之间的值。 2. 计算色相 H 在 RGB 中的值。如果 H 的范围在 0~60 或者 300~360 之间,则 R = V,G = (H/60)×V,B = 0。如果 H 的范围在 60~120 之间,则 R = ((120-H)/60)×V,G = V,B = 0。如果 H 的范围在 120~180 之间,则 R = 0,G = V,B =
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。