java 程序提问
发布网友
发布时间:2022-05-17 10:04
我来回答
共5个回答
热心网友
时间:2023-10-18 14:54
class find_best_way //继续的提问,代码太长,多次发表
{
double diggest_hormone_road_road_hormone;
int now_city=0;
int final_way[];
int m;
int n;
int pp;
int task_id;
int ni;
int nii;
int city_passed_number;
double total_distance = 0;
int city_number;
double[][][] city_link = new double[city_number + 1][city_number + 1][2];
double[][] task_information = new double[4][6];
public find_best_way(int task_id,int city_number,double city_link[][][],double task_information[][],int distance_between_two_city,int goal_city,int start_city,int task_number,int hormone_of_way)
{
this.final_way[0]=(int)task_information[task_id][start_city];
for(int ni=0;ni<=city_number;ni++)
{
for(int nii=0;nii<=city_number;nii++)
{
this.city_link[ni][nii][0]=city_link[ni][nii][0];
this.city_link[ni][nii][1]=city_link[ni][nii][1];
}
}
for(int ni=0;ni<task_number;ni++)
{
for(int nii=0;nii<8;nii++)
{
this.task_information[ni][nii]=task_information[ni][nii];
}
}
this.task_id=task_id;
this.city_number=city_number;
for (int m=0;m<city_number;m++)
{
diggest_hormone_road_road_hormone=0;
for(int n=1;n<=city_number;n++)
{
if(city_link[final_way[m]][n][hormone_of_way]>diggest_hormone_road_road_hormone)
{
int pp=0;
do
{
if (final_way[pp]==n)
{
break;
}
pp++;
}
while(pp<=m);
if(pp==m+1)
{
diggest_hormone_road_road_hormone=city_link[final_way[m]][n][hormone_of_way];
}
final_way[m+1]=n;
if(n==task_information[task_id][goal_city])
{
break;
}
total_distance=total_distance+city_link[m][n][distance_between_two_city];
}
}
if(n==task_information[task_id][goal_city])
{
break;
}
city_passed_number=m+1;
}
}//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
public class ant_my
{
public static void main(String args[])
{
double direct_distance;
int m,n,task_id;
int ant_speed=1;
final double hormone_increase=1;
final double hormone_increase_k=1.5;
final double hormone_decrease_k=0.5;
final int city_number=10;
final int initial_hormone=1;
final int ant_k=6;
double timering;
int start_city=0;
final int start_early_time=1;
final int start_last_time=2;
int goal_city=3;
final int goal_early_time=4;
final int goal_last_time=5;
int ant_number;
int current_city;
int id_of_start_city;
int id_of_goal_city;
final int total_distance=1;
final int city_passed_number=0;
int FBTGFAC_after_city=0;
int FGTBFAC_after_city=0;
final int longitude=0;
final int latitude=1;
final int time_of_next_city=0;
int number_of_city_ant_has_pass=1;
final int distance_between_two_city=0;
final int hormone_of_way=1;
final int task_number=4;
int i=1;
double [][]final_find_way_no_pinke=new double[task_number][city_number+2];int city_situs[][]={{23,53},{23,43},{4,24},{42,4},{423,54},{7,3},{5,43},{5,7},{54,34},{45,1}};
int city_link_readonly[][][]=
{
{
{999999,0},{2,0},{54,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0}
},
{
{2,0},{999999,0},{3,0},{99,0},{999999,0},{9,0},{83,0},{999999,0},{999999,0},{25,0},{999999,0}
},
{
{54,0},{3,0},{999999,0},{999999,0},{999999,0},{49,0},{44,0},{999999,0},{999999,0},{999999,0},{999999,0}
},
{
{999999,0},{99,0},{999999,0},{999999,0},{35,0},{22,0},{999999,0},{999999,0},{999999,0},{999999,0},{49,0}
},
{
{999999,0},{999999,0},{999999,0},{35,0},{999999,0},{66,0},{999999,0},{33,0},{999999,0},{999999,0},{399,0}
},
{
{999999,0},{9,0},{49,0},{22,0},{66,0},{999999,0},{99,0},{22,0},{999999,0},{999999,0},{999999,0}
},
{
{999999,0},{83,0},{44,0},{999999,0},{999999,0},{99,0},{999999,0},{92,0},{5,0},{999999,0},{69,0}
},
{
{999999,0},{999999,0},{999999,0},{999999,0},{33,0},{22,0},{92,0},{999999,0},{999999,0},{999999,0},{999999,0}
},
{
{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{57,0},{26,0}
},
{
{999999,0},{25,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{999999,0},{57,0},{999999,0},{999999,0}
},
{
{999999,0},{999999,0},{999999,0},{49,0},{399,0},{999999,0},{69,0},{999999,0},{26,0},{999999,0},{999999,0}
}
};
double task_information[][]=
{
{3,2,3,7,4,5},
{1,3,4,2,5,6},
{6,6,7,8,8,9},
{4,9,10,10,11,12}
};
//find_after_city FBTGFAC=null;
//find_after_city FGTBFAC=null;
//find_best_way find_best_way_for_nopinke=null;
for(task_id=0;task_id<task_number;task_id++)
{
id_of_start_city=(int)task_information[task_id][0];
id_of_goal_city =(int)task_information[task_id][3];
current_city =(int)task_information[task_id][0];
direct_distance=Math.sqrt(Math.pow((city_situs[(int)task_information[task_id][start_city]][longitude]-city_situs[(int)task_information[task_id][goal_city]][longitude]),2)+Math.pow((city_situs[(int)task_information[task_id][start_city]][latitude]-city_situs[(int)task_information[task_id][goal_city]][latitude]),2));
ant_number=(int)Math.round(ant_k*direct_distance);
int [][] way=new int[ant_number*2][city_number+3];
for(int b=0;b<ant_number*2;b++)
{
way[b][time_of_next_city]=0;
way[b][number_of_city_ant_has_pass]=0;
way[b][3]=0;
}
double [][][] city_link=new double[city_number+1][city_number+1][2];
for(int c=0;c<city_number;c++)
{
for(int d=0;d<city_number;d++)
{
city_link[c][d][distance_between_two_city]=city_link_readonly[c][d][distance_between_two_city];
city_link[c][d][hormone_of_way]=initial_hormone;
city_link[c][c][distance_between_two_city]=999999999;
}
}
city_link[0][(int)Math.round(task_information[task_id][start_city])][distance_between_two_city]=1;
city_link[(int)task_information[task_id][start_city]][0][distance_between_two_city]=1;
timering=Math.abs(task_information[task_id][goal_last_time]-task_information[task_id][start_early_time]);
final double time_stage=2;
int timering_number=(int)Math.ceil(timering/time_stage);
for (int j=0;j<=timering_number;j++)
{
for (int ant_id=1;ant_id<=ant_number;ant_id++)
{
if(way[ant_id][time_of_next_city]<=j)
{
find_after_city FBTGFAC=new find_after_city(ant_id,distance_between_two_city,way,city_number,ant_speed,current_city,i,number_of_city_ant_has_pass,goal_last_time,task_information,ant_number,timering,city_link, hormone_of_way,time_of_next_city,task_id);
FBTGFAC_after_city=FBTGFAC.after_city;
way[ant_id][number_of_city_ant_has_pass]++;
way[ant_id][way[ant_id][number_of_city_ant_has_pass]+3]=FBTGFAC.after_city;
}
way[ant_id][way[ant_id][number_of_city_ant_has_pass]+3]=FBTGFAC_after_city;
city_link[way[ant_id][way[ant_id][number_of_city_ant_has_pass]]][way[ant_id][way[ant_id][number_of_city_ant_has_pass]-1]][hormone_of_way]=city_link[way[ant_id][way[ant_id][number_of_city_ant_has_pass]]][way[ant_id][way[ant_id][number_of_city_ant_has_pass]-1]][hormone_of_way]+hormone_increase;
if(way[ant_id+ant_number][time_of_next_city]<=j)
{
find_after_city FGTBFAC=new find_after_city(ant_id+ant_number,distance_between_two_city,way,city_number,ant_speed,current_city,i,number_of_city_ant_has_pass,goal_last_time,task_information,ant_number,timering,city_link,hormone_of_way,time_of_next_city,task_id);
FGTBFAC_after_city=FGTBFAC.after_city;
}
way[ant_id+ant_number][way[ant_id+ant_number][number_of_city_ant_has_pass]+3]=FGTBFAC_after_city;
city_link[way[ant_id+ant_number][way[ant_id+ant_number][number_of_city_ant_has_pass]]][way[ant_id+ant_number][way[ant_id+ant_number][number_of_city_ant_has_pass]-1]][hormone_of_way]=city_link[way[ant_id+ant_number][way[ant_id+ant_number][number_of_city_ant_has_pass]]][way[ant_id+ant_number][way[ant_id+ant_number][number_of_city_ant_has_pass]-1]][hormone_of_way]+hormone_increase;
}
for (m=1;m<=city_number;m++)
{
for (n=1;n<=city_number;n++)
{
city_link[m][n][hormone_of_way]=city_link[m][n][hormone_of_way]*hormone_decrease_k;
}
}
find_best_way find_best_way_for_nopinke=new find_best_way(task_id,city_number,city_link,task_information,distance_between_two_city,goal_city,start_city,task_number,hormone_of_way);
for (m=0;m<=find_best_way_for_nopinke.city_passed_number;m++)
{
final_find_way_no_pinke[task_id][m+2]=find_best_way_for_nopinke.final_way[m];
System.out.println(find_best_way_for_nopinke.final_way[m]);
}
final_find_way_no_pinke[task_id][city_passed_number]=find_best_way_for_nopinke.city_passed_number;
final_find_way_no_pinke[task_id][total_distance]=find_best_way_for_nopinke.total_distance;
}
}
}
}
exception in thread "main" java.lang.arrayindexoutofboundsexception
at find_after_city.<init>(ant_my.java:37)
at ant_my.main(ant_my.java:314)
热心网友
时间:2023-10-18 14:54
问题呢?
热心网友
时间:2023-10-18 14:55
问题贴出来
热心网友
时间:2023-10-18 14:55
少main()无法运行
热心网友
时间:2023-10-18 14:56
你的问题多的是哦
我看你还是好好看看书
新手学JAVA关于一段程序的问题
int getCursorType() 已过时。 从 JDK version 1.1 开始,由 Component.getCursor() 取代。 int getExtendedState() 获取此 frame 的状态。 static Frame[] getFrames() 返回一个数组,包含由应用程序创建的所有 Frame。 Image getIconImage() 获取此 frame 显示在...
java项目面试常见问题?
面试java开发一般提问什么问题1、首先都是问工作经历,上一家公司的工作情况(应届生会问些学校表现、毕业设计之类的)。然后问些技术问题,JAVA基础的概念,线程、并发、网络、文件操作、数据库操作之类等等。2、java面试中经常被问到的问题有如下:简述string对象,StringBuffer、StringBuilder区分。多态的原...
编写JAVA程序遇到的问题汇总(二)
在测试Elasticsearch时,遇到了Bean冲突的问题,错误信息如下:Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'discussPostRepository' defined in null: Cannot register bean definition [Root bean: class [org.springframework.data....
java程序员新手一般面试什么问题 知乎
1、简单描述一下Log4J?2、简单描述JavaBean的特点?3、Hibernate在MVC模式中处于哪里?且它主要完成什么工作?4、列举Hibernate中常见的几种主键产生方法,并做简要说明?5、简单说说HQL与SQL的异同,试着写个例子?6、Hibernate 运行时需要获取一些底层实现的基本信息,其中几个关键属性包括哪些?7、利用Hi...
java的程序问题while(it.hasNext())中的it.hasNext……什么意思啊_百度...
这是java的迭代器的用法。it.hasNext()分为两个:it 和 .hasNext();1. it:这里应该是上文定义了一个可迭代对象 2. .hasNext(): 检查序列中是否还有元素 3. 其他Iterator用法。1)使用方法 iterator()要求容器返回一个 Iterator。第一次调用Iterator 的next()方法时,它返回序列的第一个元素。2...
哪位高手给点java题呀,就是求数学题的那种
1、从键盘输入一个正整数,按数字的相反顺序输出。2、写一条 for 语句,计数条件为 n 从 100~200,步长为 2;然后再用 while 语句实现同样的循环。3、编写一段程序,运行时向用户提问“你考了多少分?(0~100)”,接受输入后判断其等级并显示出来。判断依据如下:等级={优 (90~100 分);良...
Java初学者提问Count是1呢?
必须是1啊 ,第一次进入 while循环时 count++ 先执行了 现在 count=0;然后你输入 99 满足条件 继续进入while循环 count++ 继续执行 现在 count=1;你输入-1 不满足 循环条件 跳出 所以 count = 1
java面试提问:什么是OOP?
OOP全称Object Oriented Programming,是指面向对象程序设计,是一种计算机编程架构。OOP 的一条基本原则是计算机程序是由单个能够起到子程序作用的单元或对象组合而成。面向对象编程技术的关键性观念是它将数据及对数据的操作行为放在一起,作为一个相互依存、不可分割的整体——对象。对于相同类型的对象进行...
关于java程序员,我有几个问题想问
1:JAVA是这三种模式的基础,不代表你回了JAVA就会这三种模式。还需要努力啊骚年!!2:一个NB到须要集成两种以上服务端语言来实现的软件已经是很大的一个项目了,是有专门的C,C++程序员来开发对应的部分的 3:数据库就主流的oracle,mysql。nosql的比较简单学学就会 4:基本上差不多,打包编译方式...
java 网络编程程序问题
Socket s = ss.accept();String ip = s.getInetAddress().getHostAddress();System.out.println(ip+"...connected");//获取客户端发送过来的数据,那么要使用客户端对象的读取流来读取数据。InputStream in = s.getInputStream();byte[] buf = new byte[1024];int len = in.read(buf);Sy...