分支限界法-最大团问题和旅行背包问题java源程序(2)
point new_point_node=new_node_set.get(new_node_in);
point startpoint=this.points.get(0);
int
new_node_nowpath=old_node.get_now_path_long()+this.get_value(old_point_node, new_point_node)+this.get_value(new_point_node, startpoint);
int maybe_the_best=new_node_nowpath;
Node new_node=new Node(new_node_in, new_node_set, new_node_nowpath, maybe_the_best);
if(new_node.get_now_path_long()<this.answerpathlong){
this.answerpathlong=new_node.get_now_path_long();
enode.offer(new_node);
}
continue;
}
for(int i=old_node.get_node_in()+1;i<total_point;i++){//尝试原节点的各个分支
if(old_node.if_in_i(i, this.a, this.answerpathlong)){
int new_node_in=old_node.get_node_in()+1;
ArrayList<point> newnode_nowset=new ArrayList<>(old_node.get_now_sort());
int j=new_node_in;
this.changeij(newnode_nowset, i, j);
point old_node_to_point=old_node.get_node_point();
point new_node_to_point=newnode_nowset.get(new_node_in); int
new_maybe_the_best=old_node.get_node_answer()+this.get_value(old_node_to_point, new_node_to_point)-old_node_to_point.getshortestlong();
int
new_node_path_long=old_node.get_now_path_long()+this.get_value(old_node_to_point, new_node_to_point);
Node new_node=new Node(new_node_in, newnode_nowset, new_node_path_long, new_maybe_the_best);
enode.offer(new_node);
}
}
}
}
private void changeij(ArrayList<point> points,int i, int j) {
额,没什么好说的,自己看吧。
// TODO Auto-generated method stub
Collections.swap(points, i, j);
}
public void show(){
System.out.println(this.answer_points);
System.out.println("最优路径长度为:"+this.answerpathlong);
}
private void set_point_short_long(){
point p;
int[]value;
for(int i=0;i<this.points.size();i++){
p=this.points.get(i);
value=this.a[i];
for(int x:value){
if(x==0)continue;
if(x<p.getshortestlong())p.setshortestlong(x);
}
}
}
}
------------------------------------------------------------------------------- package 旅行售货员问题;
public class point {
private static int ids=0;
private int id;
private int shortestlong;
public point() {
super();
this.id=point.ids++;
this.shortestlong=Integer.MAX_VALUE;
}
public int getid() {
return id;
}
@Override
public String toString() {
return "顶点:"+this.id+";"; } public int getshortestlong() { return shortestlong; } public void setshortestlong(int s) { this.shortestlong = s;
额,没什么好说的,自己看吧。
}
------------------------------------------------------------------------------- package 旅行售货员问题;
import java.util.ArrayList;
public class Node implements Comparable<Node>{
private int node_in;
private point node_point;
private ArrayList<point>now_sort;
private int now_path_long;
private int node_answer;
public Node(int in, ArrayList<point> set, int p_l,int n_a) { super();
this.node_in = in;
this.now_sort = set;
this.now_path_long = p_l;
this.node_answer = n_a;
this.node_point=this.now_sort.get(in);
}
public boolean if_in_i(int i,int[][]a,int now_long){
point now_point=now_sort.get(node_in);
point pointi=now_sort.get(i);
int now_id=now_point.getid();
int pointi_id=pointi.getid();
int value=a[now_id][pointi_id];
if(value==Integer.MAX_VALUE)return false;
int
pointi_answer=this.node_answer+value-now_point.getshortestlong(); if(pointi_answer>now_long)return false;
return true;
}
public boolean if_end(int point_sum){
if(this.node_in==point_sum-1)return true;
return false;
}
public boolean if_end_father(int point_number){
if(this.node_in==point_number-2)return true;
return false;
}
public int get_now_path_long() {
return now_path_long;
额,没什么好说的,自己看吧。
public ArrayList<point> get_now_sort() {
return now_sort;
}
public int get_node_in() {
return node_in;
}
public int get_node_answer() {
return node_answer;
}
public point get_node_point() {
return node_point;
}
@Override
public int compareTo(Node o) {
if(this.node_answer>o.node_answer)return 1;
if(this.node_answer<o.node_answer)return -1;
return 0;
}
}
-----------------------------------------------------------------------
五、实验总结
(本次实验完成的情况,心得体会)
…… 此处隐藏:1852字,全部文档内容请下载后查看。喜欢就下载吧 ……相关推荐:
- [高中教育]电子线路高频非线性部分2.1
- [高中教育]中班美术活动——我的小手
- [高中教育]常用三极管参数大全
- [高中教育]计算机常见故障及解决办法
- [高中教育]风机基础环水平度控制方法探讨
- [高中教育]机械安全工程(专升本)阶段性作业3
- [高中教育]2009年安徽省高考语文考试说明刍议
- [高中教育]unit5 let's eat公开课教案设
- [高中教育]计算机网络原理课后习题答案
- [高中教育]2016-2022年中国新能源市场研究与投资
- [高中教育]2015-2020年中国会议行业市场评估及投
- [高中教育]经销商大会峰会主持人串词开场白
- [高中教育]2014新版北师大数学三年级上册小熊购物
- [高中教育]七年级第一学期体育与健康全套教案
- [高中教育]第三章:国际金融市场
- [高中教育]六年级下册数学单元测试-2.比例 北师大
- [高中教育]2016年上海海事大学法学院624刑法之《
- [高中教育]中国碳化钙产业竞争现状及未来五年投资
- [高中教育]网络时代,我们怎么玩
- [高中教育]圆锥曲线——高中数学基础知识与典型例
- 高集医院世界艾滋病宣传日活动方案
- 苏教版六年级英语上册期末试卷含答案
- 全民枪战生化英雄模式幽灵怎么玩 生化
- 灿烂的宋元文化一导学案
- 第2章货币资金与应收款项
- 北师大版八年级下册数学第三章《分式》
- 浅析高分子材料成型加工技术
- 华南理工大学2013年度共青团先进集体及
- 教师资格科目二小学教案模板(共合集)
- 工程扩建可研报告
- 中华人民共和国海事局2014年度招录公务
- 提高农村小学生作文能力的教学尝试
- 徒手心肺复苏术操作步骤
- 毛概试题库7-15章
- 2014-2015学年度(上)初中班主任工作计
- 企业驾驶员安全生产责任书
- 第07章 不等式测试题-2016年高考文科数
- 医疗器械经营企业工作程序
- 考研英语必背36篇_彩版_精华
- 初中9月13-15假期作业 (1)




