节约里程算法java实现

数据结构

  • 节约里程表
/**
 * 包含节约里程,起点、终点(节约里程表的数据结构)
 *
 */
public class Path {
	public double save_distance;//节约里程
	public int head; //起点
	public int tail;  //终点
	public Path(int head,int tail,double save_distance){
		this.head = head;
		this.tail = tail;
		this.save_distance = save_distance;
	}
	public Path(){}
}
  • 路线表
public class Route {
	/**
	 * 剩余容量
	 */
	public double residual_load;
	
	/**
	 * 路线上地点的数组
	 */
	public ArrayList route;
	
	/**
	 * 路线总路程
	 */
	public double distance_count;
}

具体算法实现

import java.util.ArrayList;
import com.tool.GetDate;
import com.bean.Path;
import com.bean.Route;

/**
 * @instruction 节约里程算法
 */
public class Distance {
	static double[][] minPath;//最短路线矩阵
	static double[] demand; //每个点的需求量
	static double whole_capacity; //最大载货量
	static int num = 5; // 配送点的数量
	static ArrayList<Route> route_result = new ArrayList<Route>(); //路线数组
	static ArrayList<Path> save_distance;//节约里程
	
	
	public static void main(String[] args) {
		// 从文件中读取最短路径矩阵和每个点的需求量(文件在data目录下,使用了com.tool中的工具类)
		minPath = GetDate.readCSV_distance();
		demand = GetDate.readCSV_demand();
		
		whole_capacity = 4; // 最大载货量
		num = 5; //配送点数量
		
		//计算节约里程
		save_distance = Distance.process(demand, minPath);
		
		//计算节约路线
		find_path();
		
		//组织输出,更符合阅读习惯(标号从0更改到1),增加起点终点
		System.out.println("-----------------------------------------");
		System.out.println("最终输出");
		int count = 0;
		for (Route r : route_result) {
			ArrayList routes = r.route;
			System.out.print("P0");
			for (int i = 0; i < routes.size(); i++) {
				int n = (int)routes.get(i) + 1;
				System.out.print("-P" + n + "-");
			}
			System.out.print("P0");
			count += r.distance_
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值