package trackerModule.sim.tracker;
import groundTruthModule.GTmodule.GTGenerator;
import groundTruthModule.datastructure.*;
import groundTruthModule.datastructure.TerroristPlan.TerroristPlanType;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.event.ActionEvent;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.Action;
import trackerModule.core.datastructure.*;
import trackerModule.core.rulestructure.*;
import trackerModule.util.ShortestPathAlgorithm;
import trackerModule.util.SortableValueMap;
import trackerModule.util.ShortestPathAlgorithm.Data;
import trackerModule.weka.WekaInterface;
/*
* Structure of TBD for the world
*
* TDBROOT.MODEL.WORLD.LOCATIONS.Karachi_Port.X
* TDBROOT.MODEL.WORLD.LOCATIONS.Karachi_Port.Y
* TDBROOT.MODEL.WORLD.LOCATIONS.Karachi_Port.WIDTH
* TDBROOT.MODEL.WORLD.LOCATIONS.Karachi_Port.HEIGHT
*
* [example]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Mission
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Location
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Type
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Destination[T0[none]]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Action[T0[none]]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.ActionTime
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.ActionTimeCount[T0[0]]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.AbnormalAction[T0[0]]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.In-Route[T0[0]]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Proximity[T0[0]]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Appearance[T0[APP1]]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Electronics
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.DetectedECM[T0[]]
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.DetectedShipsByRadar
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.IsShipOfInterest
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.X
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Y
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.DesX
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.DesY
* TDBROOT.MODEL.WORLD.SHIPS.Ship9.Crew[T0[Person9]]
* TDBROOT.MODEL.WORLD.PEOPLE
* TDBROOT.MODEL.WORLD.LOCATIONS.Karachi_Port.X[T0[150]]
* TDBROOT.MODEL.WORLD.LOCATIONS.Karachi_Port.Y[T0[150]]
* TDBROOT.MODEL.WORLD.LOCATIONS.Karachi_Port.WIDTH[T0[50]]
* TDBROOT.MODEL.WORLD.LOCATIONS.Karachi_Port.HEIGHT[T0[50]]
* TDBROOT.RUN
*
*/
/**
* The Class World.
*/
public class World extends Tracker implements IMessageObject{
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -6941357290375626796L;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// static
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** The world. */
static public World world = null;
/**
* This.
*
* @return the world
*/
static public World This(){
if( world == null )
world = new World();
return world ;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Sub class
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* The Class Tile.
*/
public class Tile implements Serializable{
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -5711635082841718895L;
/**
* Instantiates a new tile.
*
* @param n the name
* @param x0 the x0
* @param y0 the y0
* @param w the width
* @param h the height
*/
public Tile(String n, int x0, int y0, int w, int h){
name = n; x = x0; y = y0; width = w; height = h;
}
/** The name. */
public String name = "";
/** The x. */
public int x = 0;
/** The y. */
public int y = 0;
/** The width. */
public int width = 100;
/** The height. */
public int height = 100;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//map
/** The entity_ size. */
public int ENTITY_SIZE = 10;
/** The tile_ size. */
public int TILE_SIZE = 20;
/** The screen_ width. */
public int SCREEN_WIDTH = 6000;
/** The screen_ height. */
public int SCREEN_HEIGHT = 3000;
/** The map_ width. */
public int MAP_WIDTH = SCREEN_WIDTH/TILE_SIZE;
/** The map_ height. */
public int MAP_HEIGHT = SCREEN_HEIGHT/TILE_SIZE;
/** The map world. */
public String[][] mapWorld = new String[MAP_WIDTH][MAP_HEIGHT];
/** The tile map. */
public SortableValueMap<String, Tile> tileMap = new SortableValueMap<String, Tile>();
/** The map route. */
public SortableValueMap<String, boolean[][]> mapRoute = new SortableValueMap<String, boolean[][]>();
/** The list small port. */
public ArrayList<String> listSmallPort = new ArrayList<String>();
/** The list big port. */
public ArrayList<String> listBigPort = new ArrayList<String>();
/** The list area. */
public ArrayList<String> listArea = new ArrayList<String>();
/** The list merchant area. */
public ArrayList<String> listMerchantArea = new ArrayList<String>();
/** The list fishing area. */
public ArrayList<String> listFishingArea = new ArrayList<String>();
/** The list ship type. */
public ArrayList<String> listShipType = new ArrayList<String>();
/** The map nearest fishing area. */
public SortableValueMap<String, ArrayList<String>> mapNearestFishingArea = new SortableValueMap<String, ArrayList<String>>();
/** The list unusual area. */
public ArrayList<String> listUnusualArea = new ArrayList<String>();
/** The Number of visible fishing ships. */
public int NumberOfVisiableFishingShips = 0;
/** The Number of visible merchant ships. */
public int NumberOfVisiableMerchantShips = 0;
//world timer
/** The working. */
boolean working = true;
//javax.swing.Timer timer ;
//trackers
/** The weka interface. */
static WekaInterface wekaInter = null;
//Networks
/** The Shortest Path Algorithm merchant. */
ShortestPathAlgorithm spaMerchant = null;
/** The Shortest Path Algorithm area. */
ShortestPathAlgorithm spaArea = null;
/** The Shortest Path Algorithm unusual area. */
ShortestPathAlgorithm spaUnusualArea = null;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Instantiates a new world.
*/
public World() {
world = this;
initMap();
initArea();
initShipType();
initTDB();
initRouteMap();
}
/**
* Initialize the map.
*/
public void initMap() {
for(int x = 0; x < MAP_WIDTH; x++ )
for(int y = 0; y < MAP_HEIGHT; y++ ){
mapWorld[x][y] = "Water";
}
}
/**
* Initialize the area.
*/
public void initArea() {
listSmallPort.add("Sur");
listSmallPort.add("Jiwani");
listSmallPort.add("Gwadar");
listSmallPort.add("Pasni");
listSmallPort.add("Omara");
listSmallPort.add("Okha");
listSmallPort.add("Okhamadhi");
listSmallPort.add("Porbandar");
listSmallPort.add("Veraval");
listSmallPort.add("Dahanu");
listBigPort.add("Masqat");
listBigPort.add("Chabahar");
listBigPort.add("Karachi");
listBigPort.add("NaviSurat");
listBigPort.add("Mumbai");
for( String str: listBigPort ){
tileMap.put(str, new Tile(str, 30, 50, 50, 50));
}
for( String str: listSmallPort ){
tileMap.put(str, new Tile(str, 30, 50, 50, 50));
}
int i;
for( i = 0; i < 26; i++ ){
listArea.add("Area_" + i);
tileMap.put("Area_" + i, new Tile("Area_" + i, 30, 50, 30, 30));
listUnusualArea.add("UnusualArea_" + i);
tileMap.put("UnusualArea_" + i, new Tile("UnusualArea_" + i, 30, 50, 30, 30));
}
for( i = 0; i < 4; i++ ){
listMerchantArea.add("MerchantArea_" + i);
tileMap.put("MerchantArea_" + i, new Tile("MerchantArea_" + i, 30, 50, 100, 100));
}
for( i = 0; i < 38; i++ ){
listFishingArea.add("FishingArea_" + i);
tileMap.put("FishingArea_" + i, new Tile("FishingArea_" + i, 30, 50, 50, 50));
}
}
/**
* Initialize the ship type.
*/
public void initShipType(){
listShipType.add("NavyShip");
listShipType.add("FishingShip");
listShipType.add("MerchantShip");
listShipType.add("BombingFishingShip");
listShipType.add("BombingMerchantShip");
listShipType.add("IllicitCargoFishingShip");
listShipType.add("IllicitCargoMerchantShip");
}
/**
* Initialize the tdb.
*/
public void initTDB() {
TDB.This().removeAll();
//create TBD
Unit r = TDB.This().create("TDBROOT");
Unit m = r.create("MODEL");
Unit d = r.create("RUN");
Unit world = m.create("WORLD");
}
/**
* Initialize the route map.
*/
public void initRouteMap() {
mapRoute.clear();
for( String strPort: listSmallPort ){
initRouteMap( strPort+"[FishingShip]" );
}
for( String strPort: listBigPort ){
initRouteMap( strPort+"[FishingShip]" );
initRouteMap( strPort+"[MerchantShip]" );
}
initRouteMap( "MerchantArea_1[MerchantShip]" );
initRouteMap( "MerchantArea_2[MerchantShip]" );
initRouteMap( "MerchantArea_3[MerchantShip]" );
}
/**
* Initialize the route map.
*
* @param str the name
*/
public void initRouteMap(String str) {
boolean[][] map = new boolean[MAP_WIDTH][MAP_HEIGHT];
for(int x = 0; x < MAP_WIDTH; x++ )
for(int y = 0; y < MAP_HEIGHT; y++ )
map[x][y] = false;
mapRoute.put(str, map);
}
/**
* Initialize the location.
*/
public void initLocation() {
for( String str : tileMap.keySet() ){
Tile t = tileMap.get(str);
for(int x = 0; x < MAP_WIDTH; x++ ){
for(int y = 0; y < MAP_HEIGHT; y++ ){
if( t.name.equalsIgnoreCase(mapWorld[x][y])){
t.x = x;
t.y = y;
}
}
}
}
}
/**
* Initialize the shortest path.
*/
public void initShortestPath() {
spaMerchant.init();
spaArea.init();
spaUnusualArea.init();
}
/**
* Creates the shortest path.
*/
public void createShortestPath() {
//Networks
spaMerchant = new ShortestPathAlgorithm();
spaArea = new ShortestPathAlgorithm();
spaUnusualArea = new ShortestPathAlgorithm();
//spaMerchant
spaMerchant.setLineBoth("Masqat", "MerchantArea_0" , 1.0);
spaMerchant.setLineBoth("Chabahar", "MerchantArea_0" , 1.0);
spaMerchant.setLineBoth("MerchantArea_1", "MerchantArea_0" , 1.0);
spaMerchant.setLineBoth("MerchantArea_2", "MerchantArea_0" , 1.0);
spaMerchant.setLineBoth("MerchantArea_3", "MerchantArea_0" , 1.0);
spaMerchant.setLineBoth("Mumbai", "MerchantArea_1", 1.0);
spaMerchant.setLineBoth("Mumbai", "MerchantArea_2", 1.0);
spaMerchant.setLineBoth("Mumbai", "MerchantArea_3", 1.0);
spaMerchant.setLineBoth("NaviSurat", "MerchantArea_1", 1.0);
spaMerchant.setLineBoth("NaviSurat", "MerchantArea_2", 1.0);
spaMerchant.setLineBoth("NaviSurat", "MerchantArea_3", 1.0);
spaMerchant.setLineBoth("Karachi", "MerchantArea_1", 1.0);
spaMerchant.setLineBoth("Karachi", "MerchantArea_2", 1.0);
spaMerchant.setLineBoth("Karachi", "MerchantArea_3", 1.0);
//spaArea
spaArea.setLineBoth("Masqat", "Area_0" , 1.0);
spaArea.setLineBoth("Masqat", "Area_3" , 1.0);
spaArea.setLineBoth("Masqat", "Area_1" , 1.0);
spaArea.setLineBoth("Masqat", "Area_2" , 1.0);
spaArea.setLineBoth("Sur", "Area_0" , 1.0);
spaArea.setLineBoth("Sur", "Area_3" , 1.0);
spaArea.setLineBoth("Sur", "Area_25" , 1.0);
spaArea.setLineBoth("Sur", "Area_2" , 1.0);
spaArea.setLineBoth("Chabahar","Area_1" , 1.0);
spaArea.setLineBoth("Chabahar","Area_2" , 1.0);
spaArea.setLineBoth("Chabahar","Area_3" , 1.0);
spaArea.setLineBoth("Jiwani","Area_2" , 1.0);
spaArea.setLineBoth("Jiwani","Area_4" , 1.0);
spaArea.setLineBoth("Jiwani","Area_3" , 1.0);
spaArea.setLineBoth("Gwadar","Area_4" , 1.0);
spaArea.setLineBoth("Gwadar","Area_5" , 1.0);
spaArea.setLineBoth("Gwadar","Area_24" , 1.0);
spaArea.setLineBoth("Pasni","Area_5" , 1.0);
spaArea.setLineBoth("Pasni","Area_6" , 1.0);
spaArea.setLineBoth("Pasni","Area_24" , 1.0);
spaArea.setLineBoth("Omara","Area_6" , 1.0);
spaArea.setLineBoth("Omara","Area_23" , 1.0);
spaArea.setLineBoth("Omara","Area_7" , 1.0);
spaArea.setLineBoth("Karachi","Area_7" , 1.0);
spaArea.setLineBoth("Karachi","Area_23" , 1.0);
spaArea.setLineBoth("Karachi","Area_22" , 1.0);
spaArea.setLineBoth("Karachi","Area_8" , 1.0);
spaArea.setLineBoth("Okha","Area_8" , 1.0);
spaArea.setLineBoth("Okha","Area_18" , 1.0);
spaArea.setLineBoth("Okha","Area_9" , 1.0);
spaArea.setLineBoth("Okhamadhi","Area_18" , 1.0);
spaArea.setLineBoth("Okhamadhi","Area_9" , 1.0);
spaArea.setLineBoth("Okhamadhi","Area_10" , 1.0);
spaArea.setLineBoth("Porbandar","Area_10" , 1.0);
spaArea.setLineBoth("Porbandar","Area_17" , 1.0);
spaArea.setLineBoth("Porbandar","Area_11" , 1.0);
spaArea.setLineBoth("Veraval","Area_11" , 1.0);
spaArea.setLineBoth("Veraval","Area_16" , 1.0);
spaArea.setLineBoth("Veraval","Area_12" , 1.0);
spaArea.setLineBoth("NaviSurat","Area_12" , 1.0);
spaArea.setLineBoth("NaviSurat","Area_15" , 1.0);
spaArea.setLineBoth("NaviSurat","Area_13" , 1.0);
spaArea.setLineBoth("Dahanu","Area_13" , 1.0);
spaArea.setLineBoth("Dahanu","Area_15" , 1.0);
spaArea.setLineBoth("Dahanu","Area_14" , 1.0);
spaArea.setLineBoth("Mumbai","Area_15" , 1.0);
spaArea.setLineBoth("Mumbai","Area_14" , 1.0);
spaArea.setLineBoth("Area_16","Area_15" , 1.0);
spaArea.setLineBoth("Area_16","Area_17" , 1.0);
spaArea.setLineBoth("Area_17","Area_19" , 1.0);
spaArea.setLineBoth("Area_17","Area_18" , 1.0);
spaArea.setLineBoth("Area_19","Area_18" , 1.0);
spaArea.setLineBoth("Area_19","Area_20" , 1.0);
spaArea.setLineBoth("Area_21","Area_20" , 1.0);
spaArea.setLineBoth("Area_21","Area_18" , 1.0);
spaArea.setLineBoth("Area_22","Area_18" , 1.0);
spaArea.setLineBoth("Area_22","Area_23" , 1.0);
spaArea.setLineBoth("Area_21","Area_23" , 1.0);
spaArea.setLineBoth("Area_21","Area_24" , 1.0);
spaArea.setLineBoth("Area_21","Area_25" , 1.0);
spaArea.setLineBoth("Area_20","Area_25" , 1.0);
spaArea.setLineBoth("Area_3", "Area_25" , 1.0);
spaArea.setLineBoth("Area_3", "Area_24" , 1.0);
spaArea.setLineBoth("Area_25","Area_24" , 1.0);
spaArea.setLineBoth("Area_24","Area_23" , 1.0);
spaArea.setLineBoth("Area_24","Area_6" , 1.0);
spaArea.setLineBoth("Area_23","Area_7" , 1.0);
spaArea.setLineBoth("Area_22","Area_8" , 1.0);
spaArea.setLineBoth("Area_18","Area_8" , 1.0);
spaArea.setLineBoth("Area_18","Area_9" , 1.0);
spaArea.setLineBoth("Area_18","Area_10" , 1.0);
spaArea.setLineBoth("Area_17","Area_10" , 1.0);
spaArea.setLineBoth("Area_17","Area_11" , 1.0);
spaArea.setLineBoth("Area_16","Area_11" , 1.0);
spaArea.setLineBoth("Area_16","Area_12" , 1.0);
spaArea.setLineBoth("Area_15","Area_12" , 1.0);
spaArea.setLineBoth("Area_15","Area_13" , 1.0);
spaArea.setLineBoth("Area_14","Area_12" , 1.0);
spaArea.setLineBoth("Area_14","Area_15" , 1.0);
spaArea.setLineBoth("Area_14","Area_13" , 1.0);
spaArea.setLineBoth("Area_12","Area_13" , 1.0);
spaArea.setLineBoth("Area_12","Area_11" , 1.0);
spaArea.setLineBoth("Area_10","Area_11" , 1.0);
spaArea.setLineBoth("Area_10","Area_9" , 1.0);
spaArea.setLineBoth("Area_8","Area_9" , 1.0);
spaArea.setLineBoth("Area_8","Area_7" , 1.0);
spaArea.setLineBoth("Area_6","Area_7" , 1.0);
spaArea.setLineBoth("Area_6","Area_5" , 1.0);
spaArea.setLineBoth("Area_24","Area_5" , 1.0);
spaArea.setLineBoth("Area_4","Area_5" , 1.0);
spaArea.setLineBoth("Area_4","Area_24" , 1.0);
spaArea.setLineBoth("Area_4","Area_3" , 1.0);
spaArea.setLineBoth("Area_4","Area_2" , 1.0);
spaArea.setLineBoth("Area_3","Area_2" , 1.0);
spaArea.setLineBoth("Area_1","Area_2" , 1.0);
spaArea.setLineBoth("Area_1","Area_0" , 1.0);
spaArea.setLineBoth("Area_3","Area_0" , 1.0);
//unusualArea
spaUnusualArea.setLineBoth("Masqat", "UnusualArea_0" , 1.0);
spaUnusualArea.setLineBoth("Masqat", "UnusualArea_3" , 1.0);
spaUnusualArea.setLineBoth("Masqat", "UnusualArea_1" , 1.0);
spaUnusualArea.setLineBoth("Masqat", "UnusualArea_2" , 1.0);
spaUnusualArea.setLineBoth("Sur", "UnusualArea_0" , 1.0);
spaUnusualArea.setLineBoth("Sur", "UnusualArea_3" , 1.0);
spaUnusualArea.setLineBoth("Sur", "UnusualArea_25" , 1.0);
spaUnusualArea.setLineBoth("Sur", "UnusualArea_2" , 1.0);
spaUnusualArea.setLineBoth("Chabahar","UnusualArea_1" , 1.0);
spaUnusualArea.setLineBoth("Chabahar","UnusualArea_2" , 1.0);
spaUnusualArea.setLineBoth("Chabahar","UnusualArea_3" , 1.0);
spaUnusualArea.setLineBoth("Jiwani","UnusualArea_2" , 1.0);
spaUnusualArea.setLineBoth("Jiwani","UnusualArea_4" , 1.0);
spaUnusualArea.setLineBoth("Jiwani","UnusualArea_3" , 1.0);
spaUnusualArea.setLineBoth("Gwadar","UnusualArea_4" , 1.0);
spaUnusualArea.setLineBoth("Gwadar","UnusualArea_5" , 1.0);
spaUnusualArea.setLineBoth("Gwadar","UnusualArea_24" , 1.0);
spaUnusualArea.setLineBoth("Pasni","UnusualArea_5" , 1.0);
spaUnusualArea.setLineBoth("Pasni","UnusualArea_6" , 1.0);
spaUnusualArea.setLineBoth("Pasni","UnusualArea_24" , 1.0);
spaUnusualArea.setLineBoth("Omara","UnusualArea_6" , 1.0);
spaUnusualArea.setLineBoth("Omara","UnusualArea_23" , 1.0);
spaUnusualArea.setLineBoth("Omara","UnusualArea_7" , 1.0);
spaUnusualArea.setLineBoth("Karachi","UnusualArea_7" , 1.0);
spaUnusualArea.setLineBoth("Karachi","UnusualArea_23" , 1.0);
spaUnusualArea.setLineBoth("Karachi","UnusualArea_22" , 1.0);
spaUnusualArea.setLineBoth("Karachi","UnusualArea_8" , 1.0);
spaUnusualArea.setLineBoth("Okha","UnusualArea_8" , 1.0);
spaUnusualArea.setLineBoth("Okha","UnusualArea_18" , 1.0);
spaUnusualArea.setLineBoth("Okha","UnusualArea_9" , 1.0);
spaUnusualArea.setLineBoth("Okhamadhi","UnusualArea_18" , 1.0);
spaUnusualArea.setLineBoth("Okhamadhi","UnusualArea_9" , 1.0);
spaUnusualArea.setLineBoth("Okhamadhi","UnusualArea_10" , 1.0);
spaUnusualArea.setLineBoth("Porbandar","UnusualArea_10" , 1.0);
spaUnusualArea.setLineBoth("Porbandar","UnusualArea_17" , 1.0);
spaUnusualArea.setLineBoth("Porbandar","UnusualArea_11" , 1.0);
spaUnusualArea.setLineBoth("Veraval","UnusualArea_11" , 1.0);
spaUnusualArea.setLineBoth("Veraval","UnusualArea_16" , 1.0);
spaUnusualArea.setLineBoth("Veraval","UnusualArea_12" , 1.0);
spaUnusualArea.setLineBoth("NaviSurat","UnusualArea_12" , 1.0);
spaUnusualArea.setLineBoth("NaviSurat","UnusualArea_15" , 1.0);
spaUnusualArea.setLineBoth("NaviSurat","UnusualArea_13" , 1.0);
spaUnusualArea.setLineBoth("Dahanu","UnusualArea_13" , 1.0);
spaUnusualArea.setLineBoth("Dahanu","UnusualArea_15" , 1.0);
spaUnusualArea.setLineBoth("Dahanu","UnusualArea_14" , 1.0);
spaUnusualArea.setLineBoth("Mumbai","UnusualArea_15" , 1.0);
spaUnusualArea.setLineBoth("Mumbai","UnusualArea_14" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_16","UnusualArea_15" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_16","UnusualArea_17" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_17","UnusualArea_19" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_17","UnusualArea_18" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_19","UnusualArea_18" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_19","UnusualArea_20" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_21","UnusualArea_20" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_21","UnusualArea_18" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_22","UnusualArea_18" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_22","UnusualArea_23" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_21","UnusualArea_23" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_21","UnusualArea_24" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_21","UnusualArea_25" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_20","UnusualArea_25" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_3", "UnusualArea_25" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_3", "UnusualArea_24" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_25","UnusualArea_24" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_24","UnusualArea_23" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_24","UnusualArea_6" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_23","UnusualArea_7" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_22","UnusualArea_8" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_18","UnusualArea_8" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_18","UnusualArea_9" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_18","UnusualArea_10" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_17","UnusualArea_10" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_17","UnusualArea_11" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_16","UnusualArea_11" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_16","UnusualArea_12" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_15","UnusualArea_12" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_15","UnusualArea_13" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_14","UnusualArea_12" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_14","UnusualArea_15" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_14","UnusualArea_13" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_12","UnusualArea_13" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_12","UnusualArea_11" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_10","UnusualArea_11" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_10","UnusualArea_9" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_8","UnusualArea_9" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_8","UnusualArea_7" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_6","UnusualArea_7" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_6","UnusualArea_5" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_24","UnusualArea_5" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_4","UnusualArea_5" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_4","UnusualArea_24" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_4","UnusualArea_3" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_4","UnusualArea_2" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_3","UnusualArea_2" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_1","UnusualArea_2" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_1","UnusualArea_0" , 1.0);
spaUnusualArea.setLineBoth("UnusualArea_3","UnusualArea_0" , 1.0);
for( Data data : spaMerchant.arrayData ){
Tile srcTile = tileMap.get(data.src);
Tile desTile = tileMap.get(data.des);
if( srcTile != null ){
Double d = Math.sqrt((srcTile.x - desTile.x)*(srcTile.x - desTile.x) + (srcTile.y - desTile.y)*(srcTile.y - desTile.y));
data.weight = d.intValue();
}
}
for( Data data : spaArea.arrayData ){
Tile srcTile = tileMap.get(data.src);
Tile desTile = tileMap.get(data.des);
if( srcTile != null ){
Double d = Math.sqrt((srcTile.x - desTile.x)*(srcTile.x - desTile.x) + (srcTile.y - desTile.y)*(srcTile.y - desTile.y));
data.weight = d.intValue();
}
}
for( Data data : spaUnusualArea.arrayData ){
Tile srcTile = tileMap.get(data.src);
Tile desTile = tileMap.get(data.des);
if( srcTile != null ){
Double d = Math.sqrt((srcTile.x - desTile.x)*(srcTile.x - desTile.x) + (srcTile.y - desTile.y)*(srcTile.y - desTile.y));
data.weight = d.intValue();
}
}
initShortestPath();
}
/**
* Initialize the nearest fishing areas.
*/
public void initNearestFishingAreas(){
mapNearestFishingArea = new SortableValueMap<String, ArrayList<String>>();
for( String str : listSmallPort ){
Tile mainTile = tileMap.get(str);
ArrayList<String> listNearestPort = new ArrayList<String>();
findThreeNearestFishingAreas(mainTile, listNearestPort);
mapNearestFishingArea.put(str, listNearestPort);
}
for( String str : listBigPort ){
Tile mainTile = tileMap.get(str);
ArrayList<String> listNearestPort = new ArrayList<String>();
findThreeNearestFishingAreas(mainTile, listNearestPort);
mapNearestFishingArea.put(str, listNearestPort);
}
}
/**
* Find three nearest fishing areas.
*
* @param mainTile the main tile
* @param listNearestPort the list nearest port
*/
public void findThreeNearestFishingAreas(Tile mainTile, ArrayList<String> listNearestPort){
if( listNearestPort.size() == 3 )
return;
Tile r = getNearestLocation( mainTile, "FishingArea", listNearestPort );
listNearestPort.add(r.name);
findThreeNearestFishingAreas(mainTile, listNearestPort);
}
/**
* Gets the near ships.
*
* @param shipName the ship name
* @return the near ships
*/
public ArrayList<Unit> getNearShips(String shipName){
ArrayList<Unit> ret = new ArrayList<Unit>();
Unit sourceShip = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+shipName);
String strState = sourceShip.get("State").getData();
if( strState.indexOf("waiting") >=0 || strState.equalsIgnoreCase("end"))
return ret;
Integer x = sourceShip.get("X").getDataByInt();
Integer y = sourceShip.get("Y").getDataByInt();
int iDiameter = getDetectingMileForScreen();
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
for( Unit ship : ships.getList() ){
Integer x2 = ship.get("X").getDataByInt();
Integer y2 = ship.get("Y").getDataByInt();
String strState2 = ship.get("State").getData();
if( strState2.indexOf("waiting") >=0 || strState2.equalsIgnoreCase("end")){
}else{
Double d = getDistance(x, y, x2, y2);
if(d <= iDiameter/2)
ret.add(ship);
}
}
return ret;
}
/**
* Remove all instances.
*/
public void removeallInstances() {
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
if( ships != null )
ships.removeAll();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Create Ships
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Creates the ships for learning.
*
* @param shipSize the ship size
*/
public void createShipsForLearning(int shipSize) {
ENTITY_SIZE = shipSize;
Unit world = TDB.This().get("TDBROOT.MODEL.WORLD");
Unit ships = world.create("SHIPS");
ships.removeAll();
//create RDB
RDB.This().resetTime();
Rule_Unit ru = (Rule_Unit) RDB.This().get("RDBROOT");
ru.create("SHIP_RULE");
//create Ship
Ship s = null;
if( ENTITY_SIZE == 2 ){
s = new Ship("Ship"+0);
s.init("FishingShip", null, null);
s = new Ship("Ship"+1);
s.init("BombingFishingShip", null, null);
}else
if( ENTITY_SIZE == 100 ){
for(int i = 0; i < ENTITY_SIZE; i++ ){
s = new Ship("Ship"+i);
if( i<ENTITY_SIZE/2 ){
s.init("FishingShip", null, null);
}
else{
s.init("MerchantShip", null, null);
}
}
}else
{
for(int i = 0; i < ENTITY_SIZE; i++ ){
s = new Ship("Ship"+i);
if( i<40 ){
s.init("FishingShip", null, null);
}
else
if( 40 <= i && i< 80 ){
s.init("MerchantShip", null, null);
}
else
if( 80 <= i && i< 120 ){
s.init("BombingFishingShip", null, null);
}
else
if( 120 <= i && i< 160 ){
s.init("BombingMerchantShip", null, null);
}
else
if( 160 <= i && i< 200 ){
s.init("IllicitCargoFishingShip", null, null);
}
else
if( 200 <= i ){
s.init("IllicitCargoMerchantShip", null, null);
}
}
}
//set last one ship for a message receiver
RDB.This().addMessageObjectForRule(s);
//RDB.This().print("RDBROOT");
}
/**
* Creates the ships.
*
* @param shipSize the ship size
*/
public void createShips(int shipSize) {
ENTITY_SIZE = shipSize;
Unit world = TDB.This().get("TDBROOT.MODEL.WORLD");
Unit ships = world.create("SHIPS");
ships.removeAll();
//create RDB
RDB.This().resetTime();
Rule_Unit ru = (Rule_Unit) RDB.This().get("RDBROOT");
ru.create("SHIP_RULE");
//create Ship
Ship s = null;
for(int i = 0; i < ENTITY_SIZE; i++ ){
s = new Ship("Ship"+i);
s.init("BombingFishingShip", null, null);
}
//set last one ship for a message receiver
RDB.This().addMessageObjectForRule(s);
}
/*
//ship type
FishingShip
MerchantShip
BombingFishingShip
BombingMerchantShip
IllicitCargoMerchantShip
IllicitCargoFishingShip
//port type
Karachi_Port
Mumbai_Port
Masqat_Port
*/
/**
* Creates the ships by scenario.
*
* @param shipSize the ship size
* @param par the parameters
*/
public void createShipsByScenario(int shipSize, String... par) {
ENTITY_SIZE = shipSize;
Unit world = TDB.This().get("TDBROOT.MODEL.WORLD");
Unit ships = world.create("SHIPS");
ships.removeAll();
//create RDB
RDB.This().resetTime();
Rule_Unit ru = (Rule_Unit) RDB.This().get("RDBROOT");
ru.create("SHIP_RULE");
//create Ship
Ship s = null;
if( ENTITY_SIZE == 2 ){
s = new Ship("Ship"+0);
s.init("IllicitCargoFishingShip", null, "Ship"+1);
Ship s2 = new Ship("Ship"+1);
s2.init("IllicitCargoFishingShip", null, "Ship"+0);
s.initRule();
s2.initRule();
}else{
for(int i = 0; i < ENTITY_SIZE; i++ ){
s = new Ship("Ship"+i);
if( i<ENTITY_SIZE/2 ){
s.init("FishingShip", null, null);
}
else{
s.init("MerchantShip", null, null);
}
s.initRule();
}
}
//set last one ship for a message receiver
RDB.This().addMessageObjectForRule(s);
}
/**
* Creates the ships by ground truth.
*/
public void createShipsByGT() {
GTGenerator GT = new GTGenerator();
GT.createGroundTruth();
DataBase db = DataBase.getInstance();
//GT
ENTITY_SIZE = db.getShips().size();
Unit world = TDB.This().get("TDBROOT.MODEL.WORLD");
Unit ships = world.create("SHIPS");
ships.removeAll();
//create RDB
RDB.This().resetTime();
Rule_Unit ru = (Rule_Unit) RDB.This().get("RDBROOT");
ru.create("SHIP_RULE");
ArrayList<Ship> listShip = new ArrayList<Ship>();
String tempPort = null;
Ship s = null;
Map<TerroristPlan, String> mapTerroristPlan = new HashMap<TerroristPlan, String>();
for (ShipEntity ship : db.getShips()) {
s = new Ship("Ship"+ship.getID());
listShip.add(s);
if (ship.hasTerroristPlan()) {
if (ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.ExchangeIllicitCargo) {
ExchangeIllicitCargoPlan plan = (ExchangeIllicitCargoPlan)ship.getTerroristPlan();
if( mapTerroristPlan.containsKey(ship.getTerroristPlan()) )
tempPort = mapTerroristPlan.get(ship.getTerroristPlan());
if( ship.getShipType() == ShipEntity.ShipType.FISHING ){
if( tempPort == null )
tempPort = getRandomSmallPort();
else
tempPort = getRandomSmallPort(tempPort);
mapTerroristPlan.put(ship.getTerroristPlan(), tempPort);
ShipEntity s1 = plan.getMainShip();
ShipEntity s2 = plan.getSecondaryShip();
if( ship == s1 )
s.init("IllicitCargoFishingShip", tempPort, "Ship"+s2.getID());
else
s.init("IllicitCargoFishingShip", tempPort, "Ship"+s1.getID());
}
else
if( ship.getShipType() == ShipEntity.ShipType.MERCHANT ){
if( tempPort == null )
tempPort = getRandomBigPort();
else
tempPort = getRandomBigPort(tempPort);
mapTerroristPlan.put(ship.getTerroristPlan(), tempPort);
ShipEntity s1 = plan.getMainShip();
ShipEntity s2 = plan.getSecondaryShip();
if( ship == s1 )
s.init("IllicitCargoMerchantShip", tempPort, "Ship"+s2.getID());
else
s.init("IllicitCargoMerchantShip", tempPort, "Ship"+s1.getID());
}
tempPort = null;
} else if (ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.BombingPort) {
BombingPortPlan plan = (BombingPortPlan)ship.getTerroristPlan();
if( ship.getShipType() == ShipEntity.ShipType.FISHING )
s.init("BombingFishingShip", null, null);
else
if( ship.getShipType() == ShipEntity.ShipType.MERCHANT )
s.init("BombingMerchantShip", null, null);
}
}else{
if( ship.getShipType() == ShipEntity.ShipType.FISHING )
s.init("FishingShip", null, null);
else
if( ship.getShipType() == ShipEntity.ShipType.MERCHANT )
s.init("MerchantShip", null, null);
else
if( ship.getShipType() == ShipEntity.ShipType.NAVAL )
s.init("NavyShip", null, null);
}
}
for( Ship si : listShip ){
si.initRule();
}
//set last one ship for a message receiver
RDB.This().addMessageObjectForRule(s);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// set
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Sets the tile.
*
* @param x the x location
* @param y the y location
* @param tile the tile
*/
public void setTile(int x, int y, String tile) {
mapWorld[x][y] = tile;
}
/**
* Sets the route.
*
* @param str the name
* @param x the x
* @param y the y
* @param b the boolean
*/
public void setRoute(String str, int x, int y, boolean b) {
boolean[][] map = mapRoute.get(str);
map[x][y] = b;
}
/**
* Sets the weka interface.
*/
public void setWekaInterface(){
wekaInter = new WekaInterface();
wekaInter.loadBIFFromFile("world.xml");
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// get
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Gets the tile.
*
* @param x the x
* @param y the y
* @return the tile
*/
public String getTile(int x, int y) {
return mapWorld[x][y];
}
/**
* Gets the tile.
*
* @param x0 the x0
* @param y0 the y0
* @return the tile
*/
public String getTile(Double x0, Double y0) {
Integer x = x0.intValue() / TILE_SIZE;
Integer y = y0.intValue() / TILE_SIZE;
return mapWorld[x][y];
}
/**
* Gets the route.
*
* @param str the name
* @param x the x
* @param y the y
* @return the route
*/
public boolean getRoute(String str, int x, int y) {
boolean[][] map = mapRoute.get(str);
return map[x][y];
}
/**
* Gets the location.
*
* @param str the name
* @return the location
*/
public Tile getLocation(String str) {
return tileMap.get(str);
}
/**
* Gets the random big port.
*
* @param ex the exception port
* @return the random big port
*/
String getRandomBigPort(String ex) {
while( true ){
String s = getRandomBigPort();
if(!ex.equalsIgnoreCase(s))
return s;
}
}
/**
* Gets the random big port with merchant area.
*
* @param ex the exception port
* @return the random big port with merchant area
*/
String getRandomBigPortWithMerchantArea(String ex) {
while( true ){
String s = getRandomBigPortWithMerchantArea();
//if both areas are merchant area, we don't use it, because it it not reasonable in our map.
if( this.isMerchantArea(ex) && this.isMerchantArea(s) ){
}else{
if(!ex.equalsIgnoreCase(s))
return s;
}
}
}
/**
* Gets the random small port.
*
* @param ex the exception port
* @return the random small port
*/
String getRandomSmallPort(String ex) {
while( true ){
String s = getRandomSmallPort();
if(!ex.equalsIgnoreCase(s))
return s;
}
}
/**
* Gets the random big port.
*
* @return the random big port
*/
String getRandomBigPort(){
Double r = Math.random();
Double pre = 0.0;
Double cur = 0.0;
for( String str: listBigPort ){
cur = 1.0 / listBigPort.size();
if( pre < r && r <= pre + cur )
return str;
pre += cur;
}
return null;
}
/**
* Gets the random big port with merchant area.
*
* @return the random big port with merchant area
*/
String getRandomBigPortWithMerchantArea(){
Double r = Math.random();
Double pre = 0.0;
Double cur = 0.0;
for( String str: listBigPort ){
cur = 1.0 / (listBigPort.size()+3);
if( pre < r && r <= pre + cur )
return str;
pre += cur;
}
for( int i = 1; i < 4; i++ ){
cur = 1.0 / (listBigPort.size()+3);
if( pre < r && r <= pre + cur )
return "MerchantArea_"+i;
pre += cur;
}
return null;
}
/**
* Gets the random small port.
*
* @return the random small port
*/
String getRandomSmallPort(){
Double r = Math.random();
Double pre = 0.0;
Double cur = 0.0;
for( String str: listSmallPort ){
cur = 1.0 / listSmallPort.size();
if( pre < r && r <= pre + cur )
return str;
pre += cur;
}
return null;
}
/**
* Gets the random unusual area.
*
* @return the random unusual area
*/
String getRandomUnusualArea(){
Double r = Math.random();
Double pre = 0.0;
Double cur = 0.0;
for( String str: listUnusualArea ){
cur = 1.0 / listUnusualArea.size();
if( pre < r && r <= pre + cur )
return str;
pre += cur;
}
return null;
}
/**
* Gets the unusual area between.
*
* @param loc1 the location 1
* @param loc2 the location 2
* @return the unusual area between
*/
String getUnusualAreaBetween( String loc1, String loc2 ) {
Tile t1 = getLocation(loc1);
Tile t2 = getLocation(loc2);
String selected = "";
Double min = Double.POSITIVE_INFINITY;
Double cur = 0.0;
for( String str: listUnusualArea ){
Tile t3 = getLocation(str);
cur = Math.sqrt((t3.x - t1.x)*(t3.x - t1.x) + (t3.y - t1.y)*(t3.y - t1.y));
cur += Math.sqrt((t3.x - t2.x)*(t3.x - t2.x) + (t3.y - t2.y)*(t3.y - t2.y));
min = Math.min(cur, min);
if( min.equals( cur ) ){
selected = str;
}
}
return selected;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IO
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Save.
*
* @param filename the file name
*/
public void save(String filename) {
FileOutputStream fos = null;
ObjectOutputStream out = null;
try{
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(this);
out.close();
}
catch(IOException ex){
ex.printStackTrace();
}
}
/**
* Load.
*
* @param filename the file name
*/
public void load(String filename) {
FileInputStream fis = null;
ObjectInputStream in = null;
try{
initTDB();
fis = new FileInputStream(filename);
in = new ObjectInputStream(fis);
world = (World)in.readObject();
RDB.This().addMessageObjectForTime(world);
in.close();
}
catch(IOException ex){
ex.printStackTrace();
}
catch(ClassNotFoundException ex){
ex.printStackTrace();
}
initLocation();
}
/**
* Load world.
*/
public void loadWorld() {
// load TDB
load("world_v2.map");
}
/**
* Load world_ route.
*/
public void loadWorld_Route() {
load("world_v2_Route.map");
}
/**
* Save world.
*/
public void saveWorld() {
save("world_v2.map");
}
/**
* Save world_ route.
*/
public void saveWorld_Route() {
save("world_v2_Route.map");
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// thread
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* (non-Javadoc)
* @see trackerModule.core.rulestructure.IMessageObject#onUpdated(java.lang.Object)
*/
public void onUpdated(Object o) {
if( o instanceof String ){
if(((String)o).equalsIgnoreCase("SimulationFinishied")){
System.out.println("Simulation Finishied");
return;
}
}
//check all ships finished on their job
checkShipsMissionCompletion();
// if( working ){
/////////////////////////////////////////////////////////////////////////////////////////////
//learning
//tracking_LearningRoute();
//////////////////////////////////////////////////////////////////////////////////////////////
//tracker
tracking_Route();
tracking_Meeting();
tracking_VisiableShips();
//tracking_BN();
// }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// trackers
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Tracking_ route.
*/
void tracking_Route(){
//set route on the map
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
for(int i = 0; i < ENTITY_SIZE; i++ ){
Unit ship = ships.get("Ship"+i);
Integer x = ship.get("X").getDataByInt()/20;
Integer y = ship.get("Y").getDataByInt()/20;
String type = ship.get("Type").getData();
if( type.equalsIgnoreCase("FishingShip") ||
type.equalsIgnoreCase("BombingFishingShip") ||
type.equalsIgnoreCase("IllicitCargoFishingShip")){
String str = ship.get("Departure").getData()+"[FishingShip]";
if( getRoute(str, x, y) == false ){
ship.get("Route").setData("Unusual");
}
}else
if( type.equalsIgnoreCase("MerchantShip") ||
type.equalsIgnoreCase("BombingMerchantShip") ||
type.equalsIgnoreCase("IllicitCargoMerchantShip")){
String str = ship.get("Departure").getData()+"[MerchantShip]";
if( getRoute(str, x, y) == false ){
ship.get("Route").setData("Unusual");
}
}
}
}
/**
* Tracking_ meeting.
*/
void tracking_Meeting(){
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
for(int i = 0; i < ENTITY_SIZE; i++ ){
Unit ship = ships.get("Ship"+i);
Unit speed = ship.get("Speed");
String strLoc = getCurrentLocation(ship);
//
//If (ship's speed < min_sup_speed && except port area ) { check near ships in range 0.5 mile }
//
if( !listSmallPort.contains(strLoc) && !listBigPort.contains(strLoc) ){
if( speed.getDataByDouble() < 3 ){
Double x1 = ship.get("X").getDataByDouble();
Double y1 = ship.get("Y").getDataByDouble();
for(int j = 0; j < ENTITY_SIZE; j++ ){
if( i != j ){
Unit ship2 = ships.get("Ship"+j);
Unit speed2 = ship2.get("Speed");
if( speed2.getDataByDouble() < 3 ){
Double x2 = ship2.get("X").getDataByDouble();
Double y2 = ship2.get("Y").getDataByDouble();
Double dis = getDistance(x1, y1, x2, y2);
if( dis < 6 )
ship.get("Meeting").setData(ship2.getName());
}
}
}
}
}
}
}
/**
* Tracking_ visible ships.
*/
void tracking_VisiableShips(){
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
NumberOfVisiableFishingShips = 0;
NumberOfVisiableMerchantShips = 0;
for(int i = 0; i < ENTITY_SIZE; i++ ){
Unit ship = ships.get("Ship"+i);
String type = ship.get("Type").getData();
String strState = ship.get("State").getData();
if( strState.indexOf("waiting") >=0 || strState.equalsIgnoreCase("end")){
}else{
if( type.equalsIgnoreCase("FishingShip") ||
type.equalsIgnoreCase("BombingFishingShip") ||
type.equalsIgnoreCase("IllicitCargoFishingShip")){
NumberOfVisiableFishingShips++;
}else
if( type.equalsIgnoreCase("MerchantShip") ||
type.equalsIgnoreCase("BombingMerchantShip") ||
type.equalsIgnoreCase("IllicitCargoMerchantShip")){
NumberOfVisiableMerchantShips++;
}
}
}
}
/**
* Tracking_ learning route.
*/
void tracking_LearningRoute(){
//set route on the map
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
for(int i = 0; i < ENTITY_SIZE; i++ ){
Unit ship = ships.get("Ship"+i);
Integer x = ship.get("X").getDataByInt()/TILE_SIZE;
Integer y = ship.get("Y").getDataByInt()/TILE_SIZE;
String str = ship.get("Departure").getData()+"["+ship.get("Type").getData()+"]";
for( int xx = -2; xx <= 2; xx++ )
for( int yy = -2; yy <= 2; yy++ ){
setRoute(str, x+xx, y+yy, true);
}
}
}
/**
* Tracking_ bn.
*/
void tracking_BN(){
if( wekaInter != null ){
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
for(int i = 0; i < ENTITY_SIZE; i++ ){
Unit ship = ships.get("Ship"+i);
Integer x = ship.get("X").getDataByInt()/20;
Integer y = ship.get("Y").getDataByInt()/20;
String loc = ship.get("Location").getData();
wekaInter.setEvidence("X", "n"+x.toString());
wekaInter.setEvidence("Y", "n"+y.toString());
wekaInter.setEvidence("Location", loc);
// wekaInter.setEvidence("Route", ship.get("Route").getData());
// wekaInter.setEvidence("Meeting", ship.get("Meeting").getData());
Double p1 = wekaInter.getMarginal("Type", "IllicitCargoMerchantShip");
Double p2 = wekaInter.getMarginal("Type", "IllicitCargoFishingShip");
Double p3 = wekaInter.getMarginal("Type", "BombingFishingShip");
Double p4 = wekaInter.getMarginal("Type", "BombingMerchantShip");
Double p = Math.max(Math.max(p1, p2),Math.max(p3, p4));
//Double d = ship.get("SOI").getDataByDouble() + p;
ship.get("SOI").setData( p );
//System.out.println("bomb: "+p.toString() + " X: " + "n"+x.toString() +" Y: "+ "n"+y.toString() + " "+ loc);
}
}
}
/**
* Check ships mission completion.
*/
void checkShipsMissionCompletion(){
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
for(int i = 0; i < ENTITY_SIZE; i++ ){
Unit ship = ships.get("Ship"+i);
Unit state = ship.get("State");
if( !state.getData().equalsIgnoreCase("end") )
return;
}
// all ships are done
RDB.This().stop();
working = false;
}
/**
* Checks if is working.
*
* @return true, if is working
*/
public boolean isWorking() {
return working;
}
/**
* Start.
*/
public void start() {
working = true;
RDB.This().start();
}
}