📄 minpath.java
字号:
/*
* MinPath.java
*
* Created on 2007年4月22日, 下午3:16
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package mybag1;
import jade.core.Agent;
import java.util.*;
import jade.core.AID;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import java.math.*;
/**
*
* @author aying&mimi
*/
class MinPath {
private CarAgent myAgent;
// chushihualeibianliang
static final int maxLength=2000000000;//try best MAX
final int n=7;
int []s=new int[n];
int[]distance=new int[n];
double []traveltime=new double[n];
int prenode;
int backnode;
int templength;
int nextnode;
double minDis;
int u=0;
int[]path=new int[n];
//map node
static int[] nodes = { 0, 1, 3, 2, 4, 5,6 };
// chushi hua youxiangtudebian
static int[][]edge={
{0,1,1000,30,124,0},
{0,3,3000,30,124,0},
{0,4,10000,30,124,0},
{1,2,5000,40,124,0},
{2,4,1000,30,124,0},
{3,2,2000,30,124,0},
{3,4,6000,40,124,0},
{4,5,5000,30,124,0},
{3,5,1900,30,124,0},
{5,6,1000,30,124,0},
{3,6,3000,30,124,0}};
/** Creates a new instance of MinPath */
public MinPath(CarAgent agent) {
// super(agent.getLocalName());
myAgent = agent;
}
public int MinPathCal(int aNode,int bNode){
int templength=10000000;
prenode=aNode;
backnode=bNode;
//chu shi hua
for(int i=0;i<n;i++){
traveltime[i]=getTime(prenode,i);
// System.out.println("the time"+i+"is"+traveltime[i]);
s[i]=0;
if(i!=prenode&& traveltime[i]<maxLength)
path[i]=prenode;
else
path[i]=-1;
}
s[prenode]=1;
//在当前0接点中选取min longth node u
for(int i=1;i<n;i++){
minDis=maxLength;
for(int k=0;k<n;k++)
if(s[k]==0&& traveltime[k]<minDis){
u=k;
minDis= traveltime[k];
}
if(minDis==maxLength) return 0;
s[u]=1;
//xiugai cong prenode dao other node min distance and minpath
for(int j=0;j<n;j++)
if(s[j]==0&&getTime(u,j)<maxLength&& traveltime[u]+getTime(u,j)< traveltime[j]){
traveltime[j]= traveltime[u]+getTime(u,j);
path[j]=u;
// System.out.println("the time"+j+"is"+traveltime[j]);
// System.out.println("the path"+j+"is"+path[j]);
}
if(u==backnode){
int node;
int temp=10000000;
node=path[u];
if (node==prenode) nextnode=u;
else{
while(true){//dedao prenode de xia yi node
temp=path[node];
if(temp==prenode){
nextnode=node;
break;
}
else node=temp;
}
}
// templength= getLength(prenode,nextnode);
}
}
return 1;
}
int getNextNode(){
return nextnode;
}
int getLength(int a,int b){
int length=maxLength;
for(int j=0;j<11;j++){//11 yinggaiyong bianling daiti ,yihou xiugai
if(edge[j][0]==a&&edge[j][1]==b){
length=edge[j][2];
}
}
return length;
}
int getVf(int m,int n){
int vf=maxLength;
for(int k=0;k<11;k++){
if(edge[k][0]==m&&edge[k][1]==n)
vf=edge[k][3];
}
return vf;
}
int getCurQ(int m,int n){
int q=maxLength;
for(int k=0;k<11;k++){
if(edge[k][0]==m&&edge[k][1]==n)
q=edge[k][5];
}
return q;
}
int getKj(int a,int b){
int kj=maxLength;
for(int k=0;k<11;k++){
if(edge[k][0]==a&&edge[k][1]==b)
kj=edge[k][4];
}
return kj;
}
double getTime(int c,int d){
int q=0,kj;
double k,v,vf;
double time=2000000000;
DFAgentDescription template = new DFAgentDescription();
ServiceDescription sd = new ServiceDescription();
for(int i =0;i<11;i++){
// System.out.println("the ccccccccccccccccccccccccccccccccccccccccis "+c);
if(edge[i][0]==c&&edge[i][1]==d) {
vf=getVf(c,d);
kj=getKj(c,d);
int tempLength=getLength(c,d);//M
// System.out.println("the vf "+vf);
// System.out.println("the kj "+kj);
String reg;//yong lai sousuo zhuce de fuwu mingzi
reg=String.valueOf(c)+"-"+String.valueOf(d);
// System.out.println("the link "+reg);
sd.setType(reg);
template.addServices(sd);
try {
DFAgentDescription[] result = DFService.search(myAgent, template);
// System.out.println("agent is "+myAgent.getAID());
q=result.length+getCurQ(c,d);
System.out.println("the LINK OF "+c+"--"+d+" link srarching num of is "+q);
}
catch (FIPAException fe) {
fe.printStackTrace();
}
k=1000*q/tempLength;// car/KM
System.out.println("the LINK OF "+c+"--"+d+ "kkkkkkkkkkkkkkkkkkkkkkkkkkkkk "+k);
if(k<=15) {// jisuan bu qong qingkuang xia d car v
double m=1-Math.exp(-2);
v=vf*m;
}
else {
v=vf*(1-k/kj);
System.out.println("the vvvvvvvvvvvvvvvvvv !!!!!!!!!!!!!!!!!!!!!"+k/kj);
}
// else v=0.5*vf*Math.l(k/kj);
System.out.println("the vvvvvvvvvvvvvvvvvv "+c+" - "+d + "is"+v);
time=(60*tempLength)/(1000*v);
System.out.println("the tttttt"+c+" - "+d + "is" +time);
}
}
return time;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -