package park2;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.OneShotBehaviour;
import jade.core.behaviours.SimpleBehaviour;
import jade.core.behaviours.TickerBehaviour;
import jade.core.behaviours.WakerBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.domain.FIPAException;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.lang.acl.UnreadableException;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import trasmapi.genAPI.Vehicle;
import trasmapi.genAPI.temp;
import trasmapi.genAPI.exceptions.UnimplementedMethod;
import trasmapi.sumo.SumoCom;
//import trasmapi.sumo.SumoLane;
import trasmapi.sumo.SumoVehicle;
import trasmapi.sumo.vartypes.Position2D;
/**
*
* @author 17525014
*/
public class DriverAgent extends Agent{
private static final long serialVersionUID = 6095960260125307076L;
double dis1,dis2;
int DIM=120;
int pointeR=0;
Destination privat;
double prefX,prefY;
private int id;
public int delay,end,begin;
int send1,send2,rec1,rec2;
public static int numDrivers;
public boolean arrived=false;
// int counter=0;
boolean EN=true;
int FnumR,Fnumch;
ArrayList <Integer> Sum;
// ArrayList <String> VISIT;
int m;
String Sid;
sortDestination mylist;
Destination[] FlistD;
Destination[] listD;
utility mynew;
Destination myDes;
String origin;
Vehicle vehicle;
int partpointer;
evaluate eval;
char currentchar;
ArrayList<Destination> currentlist;
ArrayList<Integer> NH;
// int allocator;
int map=0;
int mn,myINDEX,MyArea;
ArrayList<Character>Visted,loser;
Character[] UTSORT1;
ArrayList<Character> listed;
Character[] partfav1;
ArrayList<Character> gangList;
evaluate[] database1;
ArrayList <evaluate>database2;
ArrayList <MR>mster;
ArrayList<Character> SP;
ArrayList<suspect>BLK;
MR CKONE;
long starttime,endtime;
double compet,tgchange;
public DriverAgent(int idDriver,Destination[] listDD) {
super();
send1=send2=rec1=rec2=0;
Sum= new ArrayList <Integer>();
NH= new ArrayList <Integer>();
database2=new ArrayList<>();
mster=new ArrayList<>();
SP=new ArrayList<>();
BLK=new ArrayList<>();
CKONE=new MR();
CKONE.name="ZERO";
gangList=new ArrayList<>();
gangList.add('r');
gangList.add('s');
gangList.add('m');
// gangList.add('n');
// gangList.add('q');
// gangList.add('t');
// VISIT= new ArrayList <String>();
FlistD= new Destination[DIM];
Visted= new ArrayList<Character>();
loser= new ArrayList<Character>();
listD=new Destination[DIM];
compet=tgchange=1;
UTSORT1=new Character[20];
myDes=new Destination();
// database=new ArrayList<evaluate>();
System.arraycopy(listDD,0,listD,0,DIM);
mn=0;
myDes=listD[0];
prefX=500.0;
prefY=500.0;
partpointer=0;
// allocator=0;
try {
this.id= idDriver;
if(idDriver%2==0){
//origin="af";
origin="af";
}else {
if(idDriver%2!=0){
origin="uv";
}
// else
// origin="di";
}
System.out.println("the start point is"+origin);
String vehicleType;
if(id>=20&&id<30)
vehicleType = SumoCom.vehicleTypesIDs.get(2);
else
vehicleType = SumoCom.vehicleTypesIDs.get(1);
String routeId = SumoCom.getRouteId(origin, null);
int departureTime;
departureTime =100;
double departPosition =5.0;
double departSpeed = 0.0;
byte departLane = 0;
vehicle = new SumoVehicle(id, vehicleType, routeId, departureTime, departPosition, departSpeed, departLane);
SumoCom.addVehicle((SumoVehicle)vehicle);
SumoCom.addVehicleToSimulation((SumoVehicle)vehicle);
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod e) {
}
}
/* (non-Javadoc)
* @see jade.core.Agent#setup()
*/
@Override
protected void setup() {
DFAgentDescription ad = new DFAgentDescription();
ad.setName(getAID()); //agentID
System.out.println("AID: "+ad.getName());
ServiceDescription sd = new ServiceDescription();
sd.setName(getName()); //nome do agente
System.out.println("Nome: "+sd.getName());
sd.setType("Driver");
System.out.println("Tipo: "+sd.getType()+"\n\n\n");
ad.addServices(sd);
Sid=id+"";
SumoCom.subscribeVehicle(Sid);
try {
DFService.register(this, ad);
} catch(FIPAException e) {
}
addBehaviour(new OneShotBehaviour() {
/**
*
*/
private static final long serialVersionUID = 1301400729516438184L;
// Position2D pos7;
//SumoVehicle ve7;
boolean F=true;
@Override
public void action(){
// ve7=SumoCom.vehicles.get(id);
while(F){
try {
if(vehicle.getSpeed()>0.0){
begin=SumoCom.getCurrentSimStep();
starttime=System.currentTimeMillis();
F=false;
mylist= new sortDestination(listD,prefX,prefY,partpointer);
FlistD= mylist.MinSpanningTree();
int i=0;
int j,z,max;
max=0;
partfav1=new Character[20];
database1=new evaluate[20];
while(i<DIM-1){
char char1=FlistD[i].destination.charAt(0);
eval=new evaluate();
j=i;
z=0;
char char2=FlistD[j].destination.charAt(0);
// System.out.println(" the value of char1 is "+char1);
//eval.size++;
while(char2==char1&&j<DIM-1){
Destination newslot=new Destination();
newslot=FlistD[j];
eval.consist.add(newslot);
eval.size++;
z++;
j++;
char2=FlistD[j].destination.charAt(0);
}
if(j==DIM-1){
Destination newslot=new Destination();
newslot=FlistD[j];
eval.consist.add(newslot);
eval.size++;
}
double bands=(eval.consist.get(z-1).x-eval.consist.get(0).x)/2;
// if(eval.selfx<0)
// eval.selfx=-1*eval.selfx;
eval.selfx=bands+eval.consist.get(0).x;
eval.selfy=eval.consist.get(0).y;
char newcar=char1;
eval.part=char1;
database1[max]=eval;
partfav1[max]=newcar;
max++;
i=j;
}
// partfav1=partfav.toArray(partfav1);
// database1=database.toArray(database1);
// for(int hj=0;hj<database.size();hj++){
// System.out.println("key: " + partfav.get(hj) + " value: " + database.get(partfav.get(hj)).consist.get(0).destination); }
//ut3=new utility(partfav,partpointer,database,ve7.position.x,ve7.position.y,allocator);
currentchar=partfav1[0];
myINDEX=0;
MyArea=0;
listed=new ArrayList<>(Arrays.asList(partfav1));
// currentchar=ut3.getutiliy();
System.out.println("the value om my LISTED is "+listed);
myDes=database1[0].consist.get(0);
System.out.println(" iam "+getLocalName()+"my destination is "+myDes.getDestination());
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (UnimplementedMethod e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
);
addBehaviour(new PeriodicSending(this,3200));
addBehaviour(new REC(this,1000));
addBehaviour(new receivingMessage());
addBehaviour(new receivingMessage2());
addBehaviour(new check());
addBehaviour(new ReceivedOffer());
addBehaviour(new OfferCancel());
addBehaviour(new SKND());
// addBehaviour(new RESPOND());
}
@Override
protected void takeDown() {
try {
DFService.deregister(this);
}
catch (FIPAException fe) {
}
System.out.println("terminating.");
}
class PeriodicSending extends TickerBehaviour{
private static final long serialVersionUID = -2919540587709502841L;
MessageTemplate tmp;
Position2D pos1;
int time1;
Vehicle ve1;
Position2D posi;
Destination sendingDes;
double desi,myx,myy;
int avl;
ArrayList<Integer> cov;
public PeriodicSending(Agent a,long t){
super(a,t);
}
@Override
public void onTick() {
ve1=SumoCom.vehicles.get(id);
try {
if(!ve1.getEdgeId().equals(myDes.destination)){
pos1=ve1.position;
myx=pos1.x;
myy=pos1.y;
cov=new ArrayList<>();
for(int ij=0;ij<numDrivers;ij++){
if(ij!=id){
posi=SumoCom.vehicles.get(ij).position;
desi=CalDis(myx,posi.x,myy,posi.y);
if(desi<=300.0){
cov.add(ij);
}
}
}
if(!cov.isEmpty()){
time1=SumoCom.getCurrentSimStep();
sendingDes=new Destination(myDes.getDestination(),myx,myy,time1);
sendingDes.BB=new ArrayList<>(BLK);
ACLMessage msg = new ACLMessage( ACLMessage.INFORM );
try {
msg.setContentObject(sendingDes);
} catch (IOException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
msg.setConversationId("park searching message");
addReceivers(msg,cov);
myAgent.send(msg);
}
}
else{
}
} catch (UnimplementedMethod e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private class receivingMessage2 extends CyclicBehaviour {
/**
*
*/
private static final long serialVersionUID = -7078137609028646000L;
MessageTemplate mx2;
Character char3;
utility ut1;
boolean found;
int map2;
double localdistance,localdistance2;
SumoVehicle ve5;
public void action() {
mx2 = MessageTemplate.MatchConversationId("NO");
ACLMessage msgg2 = myAgent.receive(mx2);
if(msgg2 != null)
{
ve5=SumoCom.vehicles.get(id);
//ve5.speed>0.0
if(!ve5.getEdgeId().equals(myDes.destination)){
Destination privat2 = null;
try {
privat2 = (Destination) msgg2.getContentObject();
} catch (UnreadableException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
// int imdex =-1;
char3=privat2.destination.charAt(0);
found=false;
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(char3)){
found=true;
map2=i;
}
}
if(found){
String[] SENDER1;
SENDER1=new String[2];
SENDER1 = msgg2.getSender().getLocalName().trim().split("#");
String Id = SENDER1[1].trim();
Integer SENDERId = Integer.parseInt(Id);
if(database1[map2].cid2.contains(SENDERId))
{
database1[map2].pointer--;
database1[map2].cid2.remove(SENDERId);
}
int bound=database1[map2].size-database1[map2].pointer;
if(bound>0){
boolean imdex =false;
int ib=-1;
for(int z=0;z<bound;z++)
{
if(database1[map2].consist.get(z).destination.equals(privat2.destination)){
imdex=true;
ib=z;
}
}
// }
if (imdex){
if(database1[map2].MA!=database1[map2].size)
database1[map2].MA=database1[map2].consist.size();
bound--;
// if(bound>0){
char mychar=myDes.destination.charAt(0);
if(char3==mychar){
if(bound<=0){
System.out.println(" ZZZZZZZZZZZZZZZZZZZZZZZZZZZ OCCUPIED STSTUS CHANGE IN "+char3+" iam "+myAgent.getLocalName());
Visted.add(mychar);
partpointer++;
if(partfav1.length-partpointer>0){
//&&gangList.contains(mychar)
if(id>=20&&id<30&&gangList.size()>1){
int gh=-1;
//if(){
int cd=0;
for(int j=0;j<partfav1.length-partpointer;j++)
if(partfav1[j]==gangList.get(0))
cd=j;
for(int j=map2;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];;
}
gh=gangList.indexOf(mychar);
gangList.remove(gh);
for(int j=0;j<partfav1.length-partpointer;j++)
if(partfav1[j]==gangList.get(0))
cd=j;
myDes=database1[cd].consist.get(0);
//}
}
else{
///////////////////////////
int xd=-1;
for(int tt=0;tt<BLK.size();tt++)
if(BLK.get(tt).SP.equals(CKONE.name))
xd=tt;
String CON=new String();
if(!CKONE.name.equals("ZERO")&&CKONE.area==myDes.destination.charAt(0)&&xd!=-1&&BLK.get(xd).rate==0.5){
// if(database1[chk].pointer<(database1[chk].size-1))
// {
// remian=database1[chk].size-database1[chk].pointer;
// System.out.println(remian+" HRAMEEEEEEEEEEEEEEEE "+myAgent.getLocalName()+" he is "+CKONE.name);
// CON=CKONE.name+"-"+CKONE.area+"-"+remian+"-"+"A";
// }
// else{
System.out.println("zero"+" SORRRRRRRRRRRRRRRY "+myAgent.getLocalName()+" he is "+CKONE.name);
CON=CKONE.name+"-"+CKONE.area+"-"+0+"-"+'B';
// }
ACLMessage MM=new ACLMessage(ACLMessage.INFORM);
MM.setContent(CON);
MM.setConversationId("scandle");
ArrayList<Integer>cov2=new ArrayList<>();
Position2D posi2;
double desi2;
for(int ij=0;ij<numDrivers;ij++){
if(ij!=id){
posi2=SumoCom.vehicles.get(ij).position;
desi2=CalDis(ve5.position.x,posi2.x,ve5.position.y,posi2.y);
if(desi2<=300.0){
cov2.add(ij); }
}
}
for(int x=0; x< cov2.size();x++){
MM.addReceiver(new AID("DRIVER#"+cov2.get(x),AID.ISLOCALNAME));
}
// MM.addReceiver(msg.getSender());
myAgent.send(MM);
}
//////////////////////////////////////
for(int j=map2;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];;
}
ut1=new utility(partfav1,partpointer,database1,ve5.position.x,ve5.position.y,compet,tgchange);
UTSORT1=ut1.getutiliy();
System.out.println(" iam "+myAgent.getLocalName()+" my list is "+Arrays.toString(UTSORT1)+" my position is "+ve5.position.x);
currentchar=UTSORT1[0];
int map = 0;
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(currentchar))
map=i;
}
mn=0;
myDes=database1[map].consist.get(mn);
}
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
else{
// for(int z=imdex;z<bound;z++)
database1[map2].pointer++;
database1[map2].consist.remove(ib);
// System.out.println(" WWWWWWWWWWWWW OCCUPIED STSTUS CHANGE IN size is "+bound+" iam "+myAgent.getLocalName()+" imdex is "+imdex+" "+char3);
if(privat2.getDestination().equals(myDes.getDestination())){
// if(bound>0){
localdistance=CalDis(database1[map2].consist.get(0).x,ve5.position.x,database1[map2].consist.get(0).y,ve5.position.x);
mn=0;
for(int k=1;k<bound;k++){
localdistance2=CalDis(database1[map2].consist.get(k).x,ve5.position.x,database1[map2].consist.get(k).y,ve5.position.y);
if(localdistance2<localdistance){
localdistance=localdistance2;
mn=k;
}
}
myDes=database1[map2].consist.get(mn);
// System.out.println(" NNNNNNNNNNNNNNNNNNNNN OCCUPIED STSTUS CHANGE IN "+char3+" iam "+myAgent.getLocalName());
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
if (mychar!=char3) {
if(bound==0)
{
int map9=0;
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(myDes.destination.charAt(0))){
map9=i;
}
}
Visted.add(char3);
partpointer++;
for(int j=map2;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];;
}
}
else{
database1[map2].pointer++;
database1[map2].consist.remove(ib);
}
}
}
}
else{
Visted.add(currentchar);
partpointer++;
if(partfav1.length-partpointer>0){
for(int j=map2;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];;
}
if(char3==myDes.destination.charAt(0)){
ut1=new utility(partfav1,partpointer,database1,ve5.position.x,ve5.position.y,compet,tgchange);
UTSORT1=ut1.getutiliy();
System.out.println(" iam "+myAgent.getLocalName()+" my list is "+Arrays.toString(UTSORT1)+" my position is "+ve5.position.x);
currentchar=UTSORT1[0];
int map = 0;
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(currentchar))
map=i;
}
mn=0;
myDes=database1[map].consist.get(mn);
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
}
else{
//System.out.println(" TERMINATE RECEIVING BEHAVIOUR ");
// myAgent.removeBehaviour(this);
}
}
// }
else
block();
}
}
private class receivingMessage extends CyclicBehaviour {
/**
*
*/
private static final long serialVersionUID = -1167565660520566700L;
MessageTemplate mx;
Position2D pos;
int time2;
double myx1,myy1;
double dis11,dis22;
String third=new String();
int parkN;
double localdistance3,localdistance4;
// int mno=0;
utility ut2;
//boolean change,change1;
temp T1;
SumoVehicle ve2;
@Override
public void action() {
mx = MessageTemplate.MatchConversationId("park searching message");
ACLMessage msgg = myAgent.receive(mx);
if(msgg != null)
{
ve2=SumoCom.vehicles.get(id);
//!myDes.getDestination().equals("ma2,5")&& !ve2.getEdgeId().equals(myDes.destination)
if(!ve2.getEdgeId().equals(myDes.destination)){
// if("park searching message".equals(msgg.getConversationId())){
Destination privat = null;
try {
privat = (Destination) msgg.getContentObject();
} catch (UnreadableException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
time2=privat.time;
T1=ve2.cache.get(time2);
pos=T1.Position;
if(ve2.position.x==pos.x&&ve2.position.y==pos.y)
pos=ve2.position;
myx1=pos.x;
myy1=pos.y;
String[] SENDER1,token2;
SENDER1=new String[2];
SENDER1 = msgg.getSender().getLocalName().trim().split("#");
String Id = SENDER1[1].trim();
Integer SENDERId = Integer.parseInt(Id);
String recived=privat.getDestination();
String park,lr;
token2=new String[2];
if(recived.equals("pp1")){
lr="p";
park="1";
}
else{
if(recived.equals("pp2")){
lr="p";
park="2";
}
else{
token2=recived.trim().split("p");
park=token2[1].trim();
lr=token2[0].trim();
}
}
int N9;
switch (lr) {
case "a": N9=1;
break;
case "b": N9=2;
break;
case "c": N9=3;
break;
case "d": N9=4;
break;
case "e": N9=5;
break;
case "f": N9=6;
break;
case "g": N9=7;
break;
case "h": N9=8;
break;
case "i": N9=9;
break;
case "j": N9=10;
break;
case "k": N9=11;
break;
case "l": N9=12;
break;
case "m": N9=13;
break;
case "n": N9=14;
break;
case "o": N9=15;
break;
case "p": N9=16;
break;
case "q": N9=17;
break;
case "r": N9=18;
break;
case "s": N9=19;
break;
case "t": N9=20;
break;
default: N9=0;
break;
}
parkN = Integer.parseInt(park);
Integer KEY;
KEY=(SENDERId)*100+N9;
boolean found2=false;
rec1++;
int map3=-1;
Character c = lr.charAt(0);
if(!Sum.contains(KEY)){
rec1++;
Sum.add(KEY);
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(c)){
found2=true;
map3=i;
}
}
if(found2){
MyArea=map3;
database1[map3].demand++;
}
boolean xx=false;
// }
/////////////////////////////////////////////////
int xc=0;
if(id>=20&&id<30){
if(SENDERId>=20&&SENDERId<30){
if(Visted.contains(c)&& !gangList.isEmpty()){
if(gangList.contains(c))
gangList.remove(c);
String CON=new String();
StringBuilder collect=new StringBuilder();
char coma=',';
collect=new StringBuilder();
collect.append(c);
collect.append(coma);
collect.append(gangList.get(0));
collect.append(coma);
collect.append('-');
collect.append(coma);
collect.append('-');
CON=collect.toString();
// ACLMessage MM=new ACLMessage(ACLMessage.INFORM);
// MM.setContent(CON);
Destination sendingDes=new Destination(CON,myx1,myy1);
ACLMessage MM = new ACLMessage( ACLMessage.INFORM );
try {
MM.setContentObject(sendingDes);
} catch (IOException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
// msg.setConversationId("park searching message");
MM.setConversationId("OFFER");
MM.addReceiver(msgg.getSender());
send2++;
myAgent.send(MM);
}
}
else{
//||privat.destination.charAt(0)=='m'|privat.destination.charAt(0)=='n'||privat.destination.charAt(0)=='q'||privat.destination.charAt(0)=='t'
if(privat.destination.charAt(0)=='r'||privat.destination.charAt(0)=='s'||privat.destination.charAt(0)=='m'){
String CON=new String();
char coma=',';
StringBuilder collect=new StringBuilder();
collect.append(c);
collect.append(coma);
collect.append('i');
collect.append(coma);
collect.append('h');
collect.append(coma);
collect.append('-');
CON=collect.toString();
// ACLMessage MM=new ACLMessage(ACLMessage.INFORM);
// MM.setContent(CON);
Destination sendingDes=new Destination(CON,myx1,myy1);
ACLMessage MM = new ACLMessage( ACLMessage.INFORM );
try {
MM.setContentObject(sendingDes);
} catch (IOException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
// msg.setConversationId("park searching message");
MM.setConversationId("OFFER");
MM.addReceiver(msgg.getSender());
send2++;
myAgent.send(MM);
}
else{
xc=1;
}
}
}
else{
int xd;
xc=1;
boolean repeat= false;
char VV = 0;
for(int i=0;i<privat.BB.size();i++){
xd=-1;
for(int tt=0;tt<BLK.size();tt++){
if(BLK.get(tt).SP.equals(privat.BB.get(i).SP))
xd=tt;
}
if(xd==-1){
suspect entry= new suspect();
entry=privat.BB.get(i);
BLK.add(entry);
for(int ii=0;ii<mster.size();ii++)
if(mster.get(ii).name.equals(entry.SP)){
repeat=true;
System.out.println(myAgent.getLocalName()+" 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx victim of "+mster.get(ii).name+" within area is "+mster.get(ii).area);
VV=mster.get(ii).area;
}
}
else{
if(BLK.get(xd).rate==0.5){
// if(!BLK.get(xd).WT.equals(privat.BB.get(i).WT)&&!privat.BB.get(i).WT.equals(third))
// third=privat.BB.get(i).WT;
// !BLK.get(xd).WT.equals(third)&&
if((!BLK.get(xd).WT.equals(privat.BB.get(i).WT))||privat.BB.get(i).rate==1){
BLK.get(xd).rate=1;
System.out.println(BLK.get(xd).SP+" if AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
}
}
if(privat.BB.get(i).rate==0){
BLK.get(xd).rate=0;
System.out.println(BLK.get(xd).SP+" if BBBBBBBBBBBBBBBBBBBB ");
}
}
}
if(repeat){
for(int j=0;j<database2.size();j++)
if(database2.get(j).consist.get(0).destination.charAt(0)==VV)
{
partfav1[partfav1.length-partpointer]=VV;
database1[partfav1.length-partpointer]=database2.get(j);
partpointer--;
database2.remove(j);
for(int y=0;y< Visted.size();y++)
if(Visted.get(y)==VV)
Visted.remove(y);
}
utility ut5=new utility(partfav1,partpointer,database1,myx1,myy1,compet,tgchange);
UTSORT1=ut5.getutiliy();
currentchar=UTSORT1[0];
int mp7=0;
for(int i=0;i<partfav1.length-partpointer;i++)
if(partfav1[i].equals(currentchar))
mp7=i;
myDes=database1[mp7].consist.get(0);
System.out.println(" i will change to "+myDes.destination.charAt(0));
myDes=database1[mp7].consist.get(0);
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
boolean ex5=true;
for(int i=0;i<BLK.size();i++)
if(BLK.get(i).SP.equals(msgg.getSender().getLocalName())&&BLK.get(i).rate==0.5)
ex5=false;
if(xc==1&&ex5){
if(Visted.contains(c)) {
String CON=new String();
char coma=',';
StringBuilder collect=new StringBuilder();
collect.append(c);
collect.append(coma);
if(partfav1.length-partpointer>=3){
collect.append(UTSORT1[1]);
collect.append(coma);
collect.append(UTSORT1[2]);
collect.append(coma);
}
else{if(partfav1.length-partpointer>=2){
collect.append(UTSORT1[1]);
collect.append(coma);
collect.append('-');
collect.append(coma);
}
}
collect.append('-');
//collect.append(partfav.get(3));
CON=collect.toString();
Destination sendingDes=new Destination(CON,myx1,myy1);
ACLMessage MM = new ACLMessage( ACLMessage.INFORM );
try {
MM.setContentObject(sendingDes);
} catch (IOException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
MM.setConversationId("OFFER");
MM.addReceiver(msgg.getSender());
send2++;
myAgent.send(MM);
}
}
//&&(myDes.destination.charAt(0)=='r'||myDes.destination.charAt(0)=='s'||myDes.destination.charAt(0)=='m'||myDes.destination.charAt(0)=='n')
//&&(myDes.destination.charAt(0)=='r'||myDes.destination.charAt(0)=='s'||myDes.destination.charAt(0)=='m'||myDes.destination.charAt(0)=='n')
if((id>=20&&id<30)&&(myDes.destination.charAt(0)=='r'||myDes.destination.charAt(0)=='s'||myDes.destination.charAt(0)=='m'))
if(!(SENDERId<=20&&SENDERId<30))
xx=true;
///////////////////////////////////////////////////////////////
/*
if(Visted.contains(c)) {
String CON=new String();
char coma=',';
StringBuilder collect=new StringBuilder();
collect.append(c);
collect.append(coma);
if(partfav1.length-partpointer>=3){
collect.append(UTSORT1[1]);
collect.append(coma);
collect.append(UTSORT1[2]);
collect.append(coma);
}
else{if(partfav1.length-partpointer>=2){
collect.append(UTSORT1[1]);
collect.append(coma);
collect.append('-');
collect.append(coma);
}
}
collect.append('-');
//collect.append(partfav.get(3));
CON=collect.toString();
Destination sendingDes=new Destination(CON,myx1,myy1);
ACLMessage MM = new ACLMessage( ACLMessage.INFORM );
try {
MM.setContentObject(sendingDes);
} catch (IOException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
// msg.setConversationId("park searching message");
MM.setConversationId("OFFER");
MM.addReceiver(msgg.getSender());
send2++;
myAgent.send(MM);
// ACLMessage MM=new ACLMessage(ACLMessage.INFORM);
// MM.setContent(CON);
// MM.setConversationId("OFFER");
// MM.addReceiver(msgg.getSender());
//send2++;
//myAgent.send(MM);
}
*/
// }
if(privat.destination.charAt(0)==myDes.getDestination().charAt(0)&&map3>-1&&!xx){
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(myDes.getDestination().charAt(0)))
map3=i;
}
dis11=CalDis(myx1,database1[map3].selfx,myy1,database1[map3].selfy);
dis22=CalDis(privat.getX(),database1[map3].selfx,privat.getY(),database1[map3].selfy);
// if(!database1[map3].cid.contains(KEY)||!privat.destination.equals(myDes.destination)){
// compet++;
// }
if((dis11>80)&&dis22>80&&!database1[map3].cid.contains(SENDERId)){
database1[map3].cid.add(SENDERId);
if(dis11>dis22){
tgchange++;
database1[map3].pointer++;
database1[map3].cid2.add(SENDERId);
if(database1[map3].MA-database1[map3].pointer==0){
partpointer++;
if(partfav1.length-partpointer>0){
loser.add(partfav1[map3]);
for(int j=map3;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];;
}
// System.out.print(" Hi "+myAgent.getLocalName()+" my demand is ");
//for(evaluate fg:database1)
// System.out.print(fg.demand+" "+fg.part+" + ");
//System.out.println("==========="+myDes.destination.charAt(0));
ut2=new utility(partfav1,partpointer,database1,ve2.position.x,ve2.position.y,compet,tgchange);
UTSORT1=ut2.getutiliy();
System.out.println(" iam "+myAgent.getLocalName()+" my list is "+Arrays.toString(UTSORT1)+" my position is "+ve2.position.x);
currentchar=UTSORT1[0];
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(currentchar))
map=i;
}
// System.out.println("next cluster destination is "+database.get(currentchar).consist.get(mno).destination+" with current size is a "+database.get(currentchar).consist.size()+" the current char is "+currentchar+" iam "+ myAgent.getLocalName());
myDes=database1[map].consist.get(0);
MyArea=map;
myDes=database1[map].consist.get(0);
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
else{
/*
if(dis11<=80&&dis22<=80){
int mp6=-1;
for(int i=0;i<partfav1.length-partpointer;i++)
if(partfav1[i].equals(myDes.destination.charAt(0)))
mp6=i;
for(int o=0;o<database1[mp6].consist.size();o++)
if (privat.getDestination().equals(database1[mp6].consist.get(o).destination))
mn=o;
// else{ if(dis11<=100&&dis22<=100){
if(database1[map3].cid2.contains(SENDERId)){
database1[map3].pointer--;
database1[map3].cid2.remove(SENDERId);
}
//boolean first=false;
if(map3>-1&&database1[map3].consist.size()>0){
if(database1[map3].MA!=database1[map3].size)
database1[map3].MA=database1[map3].size;
// for(int o=0;0<database1[map3].consist.size();o++)
// if (privat.getDestination().equals(myDes.getDestination()))
if (privat.getDestination().equals(myDes.getDestination())){
database1[mp6].cmp++;
MyArea=mp6;
dis11=CalDis(myx1,myDes.getX(),myy1,myDes.getY());
dis22=CalDis(privat.getX(),myDes.getX(),privat.getY(),myDes.getY());
// System.out.println(" the value of my distance is "+dis11+" the value of recived distance is "+dis22+" iam "+getLocalName());
if(dis11>dis22)
{
mn=-1;
int bound3=database1[mp6].size-database1[mp6].pointer;
//for(int z=0;z<bound3;z++)
//if(database1[mp6].consist.contains(privat.destination))
// mn=database1[mp6].consist.indexOf(privat.destination);
// System.out.println(" the destination is changed to becuase of "+msgg.getSender().getLocalName()+" ian "+myAgent.getLocalName());
for(int o=0;o<database1[mp6].consist.size();o++)
if (privat.getDestination().equals(database1[mp6].consist.get(o).destination))
mn=o;
database1[mp6].pointer++;
tgchange++;
bound3--;
//if(mn<database.get(map).consist.size())
if(bound3>0&&mn>-1){
//for(int zi=mn;zi<bound3;zi++)
database1[mp6].consist.remove(mn);
//database1[map3].consist.remove(mn);
// if(bound3>0){
mn=0;
localdistance3=CalDis(database1[mp6].consist.get(0).x,prefX,database1[mp6].consist.get(0).y,prefY);
for(int k=1;k<bound3;k++){
localdistance4=CalDis(database1[mp6].consist.get(k).x,prefX,database1[mp6].consist.get(k).y,prefY);
if(localdistance4<localdistance3){
localdistance3=localdistance4;
mn=k;
}
}
myDes=database1[mp6].consist.get(mn);
//database.put(currentchar,cmpeval);
// myDes=cmpeval.consist.get(mno);
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
// }
}
else{
partpointer++;
if(partfav1.length-partpointer>0){
loser.add(partfav1[mp6]);
for(int j=mp6;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];;
}
System.out.print(" Hi "+myAgent.getLocalName()+" my demand is ");
for(evaluate fg:database1)
System.out.print(fg.demand+" "+fg.part+" + ");
System.out.println("==========="+myDes.destination.charAt(0));
ut2=new utility(partfav1,partpointer,database1,ve2.position.x,ve2.position.y,compet,tgchange);
UTSORT1=ut2.getutiliy();
System.out.println(" iam "+myAgent.getLocalName()+" my list is "+Arrays.toString(UTSORT1)+" my position is "+ve2.position.x);
currentchar=UTSORT1[0];
// dt20=new dataset();
// dt20.old=myDes.destination.charAt(0);
// dt20.none=UTSORT1[0];
// dt20.happen=System.currentTimeMillis();
// dt20.doing="lose comp inside area";
// loser1.add(dt20);
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(currentchar))
map=i;
}
MyArea=map;
mn=0;
// System.out.println("next cluster destination is "+database.get(currentchar).consist.get(mno).destination+" with current size is a "+database.get(currentchar).consist.size()+" the current char is "+currentchar+" iam "+ myAgent.getLocalName());
myDes=database1[map].consist.get(mn);
if(UTSORT1[0]=='x')
{
try {
vehicle.changeTarget(origin);
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
else{
myDes=database1[map].consist.get(mn);
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
else{
//myDes=database1[map].consist[mn];
try {
vehicle.changeTarget(origin);
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
}
else{
partpointer++;
if(partfav1.length-partpointer>0){
loser.add(partfav1[map3]);
for(int j=map3;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];;
}
System.out.print(" Hi "+myAgent.getLocalName()+" my demand is ");
//for(evaluate fg:database1)
//System.out.print(fg.demand+" "+fg.part+" + ");
//System.out.println("==========="+myDes.destination.charAt(0));
ut2=new utility(partfav1,partpointer,database1,ve2.position.x,ve2.position.y,compet,tgchange);
UTSORT1=ut2.getutiliy();
System.out.println(" iam "+myAgent.getLocalName()+" my list is "+Arrays.toString(UTSORT1)+" my position is "+ve2.position.x);
currentchar=UTSORT1[0];
// dt20=new dataset();
// dt20.old=myDes.destination.charAt(0);
// dt20.none=UTSORT1[0];
// dt20.happen=System.currentTimeMillis();
// dt20.doing="loser comp because size";
// loser1.add(dt20);
for(int i=0;i<partfav1.length-partpointer;i++){
if(partfav1[i].equals(currentchar))
map=i;
}
MyArea=map;
myDes=database1[map].consist.get(0);
if(UTSORT1[0]=='x')
{
try {
vehicle.changeTarget(origin);
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
else{
myDes=database1[map].consist.get(mn);
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
else{
//myDes=database1[map].consist[mn];
try {
vehicle.changeTarget(origin);
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
*/
}
}
}
}
else{
// System.out.println(" TERMINATE RECEIVING BEHAVIOUR ");
//myAgent.removeBehaviour(this);
}
}
else{
block();
}
}
}
private void addReceivers(ACLMessage msg, ArrayList<Integer> cov)
{
for(int x=0; x< cov.size();x++){
msg.addReceiver(new AID("DRIVER#"+cov.get(x),AID.ISLOCALNAME));
}
}
public double CalDis(double x1,double x2,double y1,double y2)
{
double xDiffloc,yDiffloc,xSqrloc,ySqrloc,outputloc;
xDiffloc =x1-x2;
xSqrloc = Math.pow(xDiffloc, 2);
yDiffloc = y1-y2;
ySqrloc = Math.pow(yDiffloc, 2);
outputloc= Math.sqrt(xSqrloc + ySqrloc);
return outputloc;
}
private class check extends SimpleBehaviour {
/**
*
*/
private static final long serialVersionUID = -2639002170028439905L;
result output;
boolean C=false;
double localdistance3,localdistance4;
int counter=0;
int gy1=100;
int coonter=0;
Position2D pos3;
Vehicle ve4;
// SumoVehicle ve44;
@Override
public void action(){
ve4=vehicle;
try {
if(ve4.getEdgeId().equals(myDes.getDestination())){
C=true;
// EN=false;
// if(!myDes.getDestination().equals("ma2,5")){
try {
vehicle.setSpeed(0.0);
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
// }
counter++;
if(counter==1)
{
end=SumoCom.getCurrentSimStep();
delay=end-begin;
try {
output=new result();
} catch (IOException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
if(partfav1.length-partpointer<=0)
output.INSERT(getLocalName(),"zero",delay/100,end);
else
output.INSERT(getLocalName(),myDes.destination,delay/100,end);
/////////////////////////
int chk=-1;
for(int i=0;i<partfav1.length-partpointer;i++)
if(partfav1[i]==myDes.destination.charAt(0))
chk=i;
int remian;
String CON=new String();
if(!CKONE.name.equals("ZERO")&&CKONE.area==myDes.destination.charAt(0)){
if(database1[chk].pointer<(database1[chk].size-1))
{
remian=database1[chk].size-database1[chk].pointer;
System.out.println(remian+" HRAMEEEEEEEEEEEEEEEE "+myAgent.getLocalName()+" he is "+CKONE.name);
CON=CKONE.name+"-"+CKONE.area+"-"+remian+"-"+"A";
// }
// else{
// System.out.println("zero"+" SORRRRRRRRRRRRRRRY "+myAgent.getLocalName()+" he is "+CKONE.name);
// CON=CKONE.name+"-"+CKONE.area+"-"+0+"-"+'B';
// }
ACLMessage MM=new ACLMessage(ACLMessage.INFORM);
MM.setContent(CON);
MM.setConversationId("scandle");
ArrayList<Integer>cov2=new ArrayList<>();
Position2D posi2;
double desi2;
for(int ij=0;ij<numDrivers;ij++){
if(ij!=id){
posi2=SumoCom.vehicles.get(ij).position;
desi2=CalDis(ve4.position.x,posi2.x,ve4.position.y,posi2.y);
if(desi2<=300.0){
cov2.add(ij); }
}
}
for(int x=0; x< cov2.size();x++){
MM.addReceiver(new AID("DRIVER#"+cov2.get(x),AID.ISLOCALNAME));
}
// MM.addReceiver(msg.getSender());
myAgent.send(MM);
}
}
/////////////////////////////////////////////
}
}
// }
} catch (UnimplementedMethod e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean done(){
return C;
}
}
private class REC extends TickerBehaviour {
/**
*
*/
private static final long serialVersionUID = 1855878952337101620L;
SumoVehicle ve3;
Position2D posi2;
ArrayList<Integer> cov2;
double desi2,xvalue,yvalue;
Position2D pp;
Destination sendingDes2;
public REC(Agent a,long t){
super(a,t);
}
protected void onTick() {
ve3=SumoCom.vehicles.get(id);
if(ve3.getEdgeId().equals(myDes.getDestination())){
pp=vehicle.position;
xvalue=pp.x;
yvalue=pp.y;
cov2=new ArrayList<>();
for(int ij=0;ij<numDrivers;ij++){
if(ij!=id){
posi2=SumoCom.vehicles.get(ij).position;
desi2=CalDis(xvalue,posi2.x,yvalue,posi2.y);
if(desi2<=70.0){
cov2.add(ij); }
}
}
//!cov2.isEmpty()
if(!cov2.isEmpty()){
sendingDes2=new Destination(myDes.getDestination(),xvalue,yvalue);
ACLMessage msg2 = new ACLMessage( ACLMessage.INFORM );
try {
msg2.setContentObject(sendingDes2);
} catch (IOException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
msg2.setConversationId("NO");
for(int x=0; x< cov2.size();x++){
msg2.addReceiver(new AID("DRIVER#"+cov2.get(x),AID.ISLOCALNAME));
}
myAgent.send(msg2);
}
}
}
}
private class ReceivedOffer extends CyclicBehaviour {
private static final long serialVersionUID = 3843825647082669218L;
Vehicle ve10;
double localdistance5,localdistance6;
char partprop;
int offerid;
int number;
utility ut5;
String ENT;
char mypart;
proposal prop1;
int mp7=0;
//ArrayList<proposal> PROP=new ArrayList<proposal>();
//int fav,i;
String[] token=new String[4];
public void action() {
MessageTemplate mt =MessageTemplate.and(MessageTemplate.MatchConversationId("OFFER"),
MessageTemplate.MatchPerformative(ACLMessage.INFORM));
//MessageTemplate.MatchPerformative(ACLMessage.CFP);
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
ve10=SumoCom.vehicles.get(id);
try {
if(!ve10.getEdgeId().equals(myDes.destination)){
Destination privat = null;
try {
privat = (Destination) msg.getContentObject();
} catch (UnreadableException ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
//PROP=new ArrayList<proposal>();
rec2++;
String [] SENDER1=new String[2];
SENDER1 = msg.getSender().getLocalName().trim().split("#");
String Id = SENDER1[1].trim();
Integer SENDERId = Integer.parseInt(Id);
String title =privat.destination;
token=title.trim().split(",");
String park=token[0].trim();
mypart=park.charAt(0);
for(int i=0;i<partfav1.length-partpointer;i++)
if(partfav1[i].equals(myDes.destination.charAt(0)))
mp7=i;
boolean accept=false;
localdistance5=CalDis(ve10.position.x,database1[mp7].selfx,database1[mp7].selfy,ve10.position.y);
if(localdistance5<100)
accept=true;
boolean ref=true;
//&&(myDes.destination.charAt(0)=='r'||myDes.destination.charAt(0)=='s'||myDes.destination.charAt(0)=='m'||myDes.destination.charAt(0)=='n')
if(id>=20&&id<30)
if(!(SENDERId>=20&&SENDERId<30))
ref=false;
if(mypart==myDes.destination.charAt(0)&&!accept&&ref&& partfav1.length-partpointer>2){
//if(database1[mp7].cmp==0){
//Visted.add(partfav1[mp7]);
loser.add(partfav1[mp7]);
if(partfav1.length-partpointer>0){
prop1=new proposal();
int z=1;
boolean fe=false;
partprop=token[z].trim().charAt(0);
while(partprop!='-'&&token[z]!=null){
number=0;
while(number<partfav1.length-partpointer){
if(partfav1[number]==(partprop))
fe=true;
number++;
}
if(fe){
prop1.offer.add(partprop);
fe=false;
}
else{
// System.out.println("HI HI HI THI INFORCHANT "+z+"*******************************"+msg.getSender().getLocalName());
ACLMessage MM=new ACLMessage(ACLMessage.INFORM);
String CON="thank but-"+partprop+"-Occupied";
MM.setContent(CON);
MM.setConversationId("cancel");
MM.addReceiver(msg.getSender());
myAgent.send(MM);
}
z++;
partprop=token[z].trim().charAt(0);
}
///////////////////////////////////////////////////////
if(!prop1.offer.isEmpty())
ref=VER(ve10.position,privat.x,privat.y,prop1.offer.get(0));
boolean ex3=true;
for(int i=0;i<BLK.size();i++)
if(BLK.get(i).SP.equals(msg.getSender().getLocalName())&&BLK.get(i).rate==0.5)
ex3=false;
if(ref&&ex3&&!CKONE.name.equals(msg.getSender().getLocalName())){
MR ckf= new MR();
ckf.name=msg.getSender().getLocalName();
ckf.area=myDes.destination.charAt(0);
mster.add(ckf);
if(!prop1.offer.isEmpty()){
Visted.add(partfav1[mp7]);
partpointer++;
evaluate reme=new evaluate();
reme=database1[mp7];
database2.add(reme);
for(int j=mp7;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];
}
currentchar=prop1.offer.get(0);
offerid=-1;
System.out.println(myAgent.getLocalName()+" HI HI 333 HI THANK THANK THANK*******"+ title+" from "+msg.getSender().getLocalName());
for(int i=0;i<partfav1.length-partpointer;i++)
if(partfav1[i]==(currentchar)){
offerid=i;
}
if(offerid!=-1){
map=offerid;
myDes=database1[map].consist.get(0);
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
else{
System.out.println(myAgent.getLocalName()+" HI HI HI THANK THANK THANK******* "+ prop1.offer.get(0)+" from "+msg.getSender().getLocalName()+" received message "+title);
for(int i=0;i<partfav1.length-partpointer;i++)
System.out.print(" ******* "+ partfav1[i]+" ");
}
}
else{
Visted.add(partfav1[mp7]);
evaluate reme=new evaluate();
reme=database1[mp7];
database2.add(reme);
partpointer++;
for(int j=mp7;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];
}
System.out.println(" ALREADY IS REMOVED "+myAgent.getLocalName());
ut5=new utility(partfav1,partpointer,database1,ve10.position.x,ve10.position.y,compet,tgchange);
UTSORT1=ut5.getutiliy();
currentchar=UTSORT1[0];
// int mp7=0;
for(int i=0;i<partfav1.length-partpointer;i++)
if(partfav1[i].equals(currentchar))
mp7=i;
myDes=database1[mp7].consist.get(0);
myDes=database1[mp7].consist.get(0);
try {
vehicle.changeTarget(myDes.getDestination());
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
else {
System.out.println("MALICIOUS "+myAgent.getLocalName()+" he is "+msg.getSender().getLocalName());
CKONE.name=msg.getSender().getLocalName();
CKONE.area=myDes.destination.charAt(0);
ENT=new String();
ENT=msg.getSender().getLocalName();
int xd=-1;
for(int tt=0;tt<BLK.size();tt++){
if(BLK.get(tt).SP.equals(ENT)){
xd=tt;
}
}
if(xd==-1){
suspect ER=new suspect();
ER.SP=ENT;
ER.WT=myAgent.getLocalName();
BLK.add(ER);
}else{
if(BLK.get(xd).rate==0.5&&!BLK.get(xd).WT.equals(myAgent.getLocalName())){
BLK.get(xd).rate=1;
}
}
}
}
else{
//myDes=database1[map].consist[mn];
try {
vehicle.changeTarget(origin);
} catch (UnimplementedMethod ex) {
Logger.getLogger(DriverAgent.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
// else
//myAgent.removeBehaviour(this);
} catch (UnimplementedMethod e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
block();
}
}
private class OfferCancel extends CyclicBehaviour {
/**
*
*/
private static final long serialVersionUID = 2965006172552026401L;
SumoVehicle ve11;
//double localdistance7,localdistance8;
String[] mody=new String[3];
public void action() {
MessageTemplate mt =MessageTemplate.and(MessageTemplate.MatchConversationId("cancel"),
MessageTemplate.MatchPerformative(ACLMessage.INFORM));
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
ve11=SumoCom.vehicles.get(id);
if(!ve11.getEdgeId().equals(myDes.destination)){
//PROP=new ArrayList<proposal>();
String title2 = msg.getContent();
mody=title2.trim().split("-");
String park=mody[1].trim();
int mp10=0;
boolean right=false;
for(int i=0;i<partfav1.length-partpointer;i++)
if(partfav1[i].equals(park)){
mp10=i;
right=true;
}
if(right){
// System.out.println(" ###################+++++++++++++++++++++++++++TROUBLE____%%%%%%%%%%%%%%%%%%%%%%%%***********************");
partpointer++;
for(int j=mp10;j<partfav1.length-partpointer;j++){
database1[j]=database1[j+1];
partfav1[j]=partfav1[j+1];;
}
}
}
// else
// myAgent.removeBehaviour(this);
}
else
block();
}
}
boolean VER(Position2D myposi, double youx,double youy, char PAR){
boolean finalD=false;
double dis1, dis2,Cstate=-1,near,DISION;
int IN=-1,myArea=-1;
dis1=CalDis(myposi.x,database1[0].selfx,myposi.y,database1[0].selfy);
for(int i=1;i<partfav1.length-partpointer;i++){
dis2=CalDis(myposi.x,database1[i].selfx,myposi.y,database1[i].selfy);
if(dis1>=dis2){
dis1=dis2;
myArea=i;
}
if(PAR==partfav1[i])
IN=i;
}
if(myArea>-1){
Cstate=(double)database1[myArea].pointer/(double)database1[myArea].size;
}
else{
Cstate=1;
}
if(IN>-1)
{
dis1=CalDis(myposi.x,database1[IN].selfx,myposi.y,database1[IN].selfy);
dis2=CalDis(youx,database1[IN].selfx,youy,database1[IN].selfy);
near=dis1/dis2;
}
else return finalD;
DISION=Cstate+near;
if(DISION>1)
finalD=true;
System.out.println(" ###################++++++++++++++++++++++ "+near+" "+Cstate);
return finalD;
}
private class SKND extends CyclicBehaviour {
/**
*
*/
private static final long serialVersionUID = 2965006172552026401L;
SumoVehicle ve11;
//double localdistance7,localdistance8;
String[] mody=new String[4];
public void action() {
MessageTemplate mt =MessageTemplate.and(MessageTemplate.MatchConversationId("scandle"),
MessageTemplate.MatchPerformative(ACLMessage.INFORM));
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
ve11=SumoCom.vehicles.get(id);
if(!ve11.getEdgeId().equals(myDes.destination)){
//PROP=new ArrayList<proposal>();
String title2 = msg.getContent();
mody=title2.trim().split("-");
//System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^ i am "+myAgent.getLocalName()+" i got a message from "+msg.getSender().getLocalName()+" which is content "+msg.getContent());
String park=mody[0].trim();
String ELG=new String();
ELG=mody[3].trim();
int xd=-1;
for(int tt=0;tt<BLK.size();tt++){
if(BLK.get(tt).SP.equals(park))
xd=tt;
}
if(xd==-1){
suspect dd=new suspect();
if(ELG.charAt(0)=='A')
dd.rate=1;
else
dd.rate=0;
dd.SP=park;
dd.WT=msg.getSender().getLocalName();
}else{
if(ELG.charAt(0)=='A')
BLK.get(xd).rate=1;
else
//if(BLK.get(xd).rate==0.5)
BLK.get(xd).rate=0;
}
// String entey=new String();
// entey=park;
// BLK.add(entey);
for(int i=0;i<mster.size();i++)
if(mster.get(i).name.equals(park))
System.out.println(myAgent.getLocalName()+" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx victim of "+mster.get(i).name+" within area is "+mster.get(i).area);
}
// else
// myAgent.removeBehaviour(this);
}
else
block();
}
}
////////////////////////////
}