package groundTruthModule.GTmodule;
import groundTruthModule.datastructure.BombingPortPlan;
import groundTruthModule.datastructure.DataBase;
import groundTruthModule.datastructure.ExchangeIllicitCargoPlan;
import groundTruthModule.datastructure.OrganizationEntity;
import groundTruthModule.datastructure.PersonEntity;
import groundTruthModule.datastructure.PersonEntity.ClusterPartition;
import groundTruthModule.datastructure.PersonEntity.EconomicStanding;
import groundTruthModule.datastructure.PersonEntity.EducationLevel;
import groundTruthModule.datastructure.PersonEntity.FamilyStatus;
import groundTruthModule.datastructure.PersonEntity.Nationality;
import groundTruthModule.datastructure.PersonEntity.Occupation;
import groundTruthModule.datastructure.PersonEntity.Quantity;
import groundTruthModule.datastructure.ShipEntity;
import groundTruthModule.datastructure.ShipEntity.ShipType;
import groundTruthModule.datastructure.TerroristPlan;
import groundTruthModule.datastructure.TerroristPlan.TerroristPlanType;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import trackerModule.core.datastructure.TDB;
import trackerModule.core.datastructure.Unit;
import trackerModule.core.rulestructure.IMessageObject;
import trackerModule.core.rulestructure.RDB;
import unbbayes.io.xmlbif.version7.BaseXMLBIFIO;
import unbbayes.prs.bn.PotentialTable;
import unbbayes.prs.bn.ProbabilisticNetwork;
import unbbayes.prs.bn.ProbabilisticNode;
/*
* author: Aditya Mugali
* generates ground truth
*/
public class GTGenerator implements IMessageObject {
private DataBase db;
private ProbabilisticNetwork pn;
public GTGenerator() {
db = DataBase.getInstance();
init();
}
private void init() {
nNavalShips = (int) (pNavalShips * nShips);
nFishingShips = (int) (pFishingShips * nShips);
nMerchantShips = (int) (pMerchantShips * nShips);
nPeople = nShips + navalCrewSize * nNavalShips + fishingCrewSize
* nFishingShips + merchantCrewSize * nMerchantShips;
nTerroristPlans = (int) (pTerroristPlans * (nFishingShips + nMerchantShips));
nTerroristPlans = (minTerroristPlans > nTerroristPlans ? minTerroristPlans
: nTerroristPlans);
}
/*
* Test configuration
250 ship case
1. 25 organization 10-5-10
2. 500 organization 25-5-10
3. 1000 organization 100-10-20
500 ship case
1. 25 organization 10-5-10
2. 500 organization 25-5-10
3. 1000 organization 100-10-20
*/
private int nShips = 500;
private int nOrganizations = 25;
private int navalCrewSize = 10;
private int fishingCrewSize = 5;
private int merchantCrewSize = 10;
private float pNavalShips = .1f;
private float pFishingShips = .5f;
private float pMerchantShips = .4f;
private int nNavalShips;
private int nFishingShips;
private int nMerchantShips;
private int nPeople;
private float pTerroristPlans = .01f;
private int minTerroristPlans = 2;
private int nTerroristPlans;
/*
* randomly generate Ground Truth data
*/
public void createGroundTruth() {
generatePeople();
generateShips();
generateOrganizations(nOrganizations);
generateSocialNetwork();
associateOrganizations();
associateShipCrew();
initPNNetwork();
populateEntities(1);
printSuspiciousData();
// printGroundTruthData();
// printRelations();
RDB.This().addMessageObjectForTime(this);
}
private void printSuspiciousData() {
System.out.println();
System.out.println("***** BEGIN SUSPICIOUS DATA *****");
for (OrganizationEntity org : db.getOrganizations()) {
if (org.isTerroristOrganisation()) {
System.out.println("Organization "
+ db.getOrganizations().indexOf(org)
+ " is a terrorist organization.");
for (PersonEntity person : org.getMembers()) {
if (person.isTerrorist()) {
System.out.println("\tPerson " + db.getPeople().indexOf(person)
+ " is a terrorist member.");
}
}
}
}
List<TerroristPlan> listOfPlans = new ArrayList<TerroristPlan>();
for (ShipEntity ship : db.getShips()) {
if (ship.hasTerroristPlan()) {
if (!listOfPlans.contains(ship.getTerroristPlan())) {
if (ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.ExchangeIllicitCargo) {
ExchangeIllicitCargoPlan plan = (ExchangeIllicitCargoPlan)ship.getTerroristPlan();
System.out.println("Exchange Illicit Cargo Plan: ");
System.out.println("\tShip "
+ db.getShips().indexOf(plan.getMainShip())
+ " is the main ship of type "
+ plan.getMainShip().getShipType()
+ (plan.getMainShip().isHijacked() ? " and was hijacked " : " and has a terrorist crew member."));
if (!plan.getMainShip().isHijacked()) {
for (PersonEntity person : plan.getMainShip().getCrew()) {
if (person.isTerrorist()) {
System.out.println("\t\tPerson " + db.getPeople().indexOf(person)
+ " is a terrorist crew member.");
}
}
}
System.out.println("\tShip "
+ db.getShips().indexOf(plan.getSecondaryShip())
+ " is the secondary ship of type "
+ plan.getSecondaryShip().getShipType()
+ (plan.getSecondaryShip().isHijacked() ? " and was hijacked " : " and has a terrorist crew member."));
if (!plan.getSecondaryShip().isHijacked()) {
for (PersonEntity person : plan.getSecondaryShip().getCrew()) {
if (person.isTerrorist()) {
System.out.println("\t\tPerson " + db.getPeople().indexOf(person)
+ " is a terrorist crew member.");
}
}
}
} else if (ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.BombingPort) {
BombingPortPlan plan = (BombingPortPlan)ship.getTerroristPlan();
System.out.println("Bombing Port Plan: ");
System.out.println("\tShip "
+ db.getShips().indexOf(plan.getShip())
+ " is the suicide ship of type "
+ plan.getShip().getShipType()
+ (plan.getShip().isHijacked() ? " and was hijacked " : " and has a terrorist crew member."));
if (!plan.getShip().isHijacked()) {
for (PersonEntity person : plan.getShip().getCrew()) {
if (person.isTerrorist()) {
System.out.println("\t\tPerson " + db.getPeople().indexOf(person)
+ " is a terrorist crew member.");
}
}
}
}
listOfPlans.add(ship.getTerroristPlan());
}
}
}
System.out.println("***** END SUSPICIOUS DATA *****");
System.out.println();
}
/**
* prints people relationships
*/
private void printRelations() {
for (PersonEntity pe : db.getPeople())
// System.out.println("relation size is "+pe.getIsRelatedTo().size());
for (PersonEntity pe2 : pe.getIsRelatedTo())
System.out.println("The related person to "
+ db.getPeople().indexOf(pe) + " is "
+ pe.getIsRelatedTo().indexOf(pe2));
}
/**
* Associate ship to crew
*/
private void associateShipCrew() {
for (ShipEntity ship : db.getShips()) {
int crewSize = 0;
if (ship.getShipType() == ShipType.NAVAL) {
crewSize = navalCrewSize;
} else if (ship.getShipType() == ShipType.FISHING) {
crewSize = fishingCrewSize;
} else {
crewSize = merchantCrewSize;
}
for (int i = 0; i < crewSize; i++) {
int rand = getRandom(0, nPeople - 1);
if (!isCrewMemberOfSomeShip(db.getPeople().get(rand)))
ship.addCrew(db.getPeople().get(rand));
}
}
}
/**
*
* @param personEntity
* @return true if any ship contains this person - i.e., true if this person
* is already a crew member of some ship.
*/
private boolean isCrewMemberOfSomeShip(PersonEntity personEntity) {
for (ShipEntity ship : db.getShips())
if (ship.getCrew().contains(personEntity))
return true;
return false;
}
/**
* Load the Bayesian Network
*/
private void initPNNetwork() {
try {
// XMLBIFIO io = new XMLBIFIO();
BaseXMLBIFIO io = new BaseXMLBIFIO();
// Change the file here
File file = null;
try {
file = new java.io.File(getClass().getResource(
"/bn/SimulationBN-v13.xml").getFile());
} catch (NullPointerException e) {
// OK, we can still look for other places
}
if (file == null || !file.exists()) {
file = new java.io.File("bn/SimulationBN-v13.xml");
}
if (file == null || !file.exists()) {
file = new java.io.File("/bn/SimulationBN-v13.xml");
}
pn = io.load(file);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
/**
* Get a random ship from the specified type, which does not have a terrorist
* plan yet.
* @param shipType The type of the random ship to get.
* @return a ship of the given type that does not have a terrorist plan yet.
*/
private ShipEntity getRandomShip(ShipType shipType) {
int rand = getRandom(0, nShips - 1);
ShipEntity ship = db.getShips().get(rand);
// Keep trying to get a random ship of shipType.
while (ship.getShipType() != shipType || ship.hasTerroristPlan()) {
rand = getRandom(0, nShips - 1);
ship = db.getShips().get(rand);
}
return ship;
}
/**
* In a exchange illicit cargo plan, we have a main merchant ship meeting
* either another merchant ship or a fishing ship for exchanging the illicit
* cargo
*/
private void generateExchangeIllicitCargoPlan(ExchangeIllicitCargoPlan plan) {
// Choose a random merchant ship as the main ship
ShipEntity mainShip = getRandomShip(ShipType.MERCHANT);
mainShip.setTerroristPlan(plan);
plan.setMainShip(mainShip);
mainShip.setShipOfInterest(true);
// Define the reason for terrorist plan: the ship was hijacked
// or there is a terrorist crew member
// Let's assume 50% chance for each
if (Math.random() <= 1 / 2f) {
mainShip.setHijacked(true);
} else {
mainShip.setHijacked(false);
assignTerroristCrewMember(mainShip);
}
// Define which ship is going to meet the main ship, in other words, the
// secondary ship. It can be either a fishing or merchant ship. Let's
// assume 50% chance for each.
ShipEntity secondaryShip;
if (Math.random() <= 1 / 2f) {
secondaryShip = getRandomShip(ShipType.FISHING);
} else {
secondaryShip = getRandomShip(ShipType.MERCHANT);
}
secondaryShip.setTerroristPlan(plan);
plan.setSecondaryShip(secondaryShip);
secondaryShip.setShipOfInterest(true);
// Define the reason for terrorist plan on secondary ship: the ship was
// hijacked or there is a terrorist crew member
// Let's assume 50% chance for each
if (Math.random() <= 1 / 2f) {
secondaryShip.setHijacked(true);
} else {
secondaryShip.setHijacked(false);
assignTerroristCrewMember(secondaryShip);
}
// Define the attributes of the main ship based on its normal behavior
// for this type of plan.
// The main behaviors present are:
// 1. Meeting another ship -> so unusual route is likely
generateDataForUnusualRoute(mainShip);
// 2. Evasive behavior
generateDataForEvasiveBehavior(mainShip);
// 3. Erratic behavior
generateDataForErraticBehavior(mainShip);
// 4. Aggressive behavior
generateDataForAggressiveBehavior(mainShip);
// Define the attributes of the secondary ship based on its normal
// behavior
// for this type of plan.
// If the secondary ship is a merchant ship, then the main behaviors
// are:
// 1. Meeting another ship -> so unusual route is likely
// 2. Evasive behavior
// 3. Erratic behavior
// 4. Aggressive behavior
// However, if the secondary ship is a fishing ship, then the main
// behaviors are:
// 1. Meeting another ship -> so unusual route is likely
// 2. Aggressive behavior
// Nevertheless, we need to generate data for all attributes, therefore
// we need to call the generate data for all possible behaviors.
generateDataForUnusualRoute(secondaryShip);
generateDataForEvasiveBehavior(secondaryShip);
generateDataForErraticBehavior(secondaryShip);
generateDataForAggressiveBehavior(secondaryShip);
}
/**
* In a exchange bombing port plan, a ship is going to be a suicide ship to
* bomb a port, which is different than the original destination port.
*/
private void generateBombingPortPlan(BombingPortPlan plan) {
// Choose a random merchant ship as the suicide ship
ShipEntity ship = getRandomShip(ShipType.MERCHANT);
ship.setTerroristPlan(plan);
plan.setShip(ship);
ship.setShipOfInterest(true);
// Define the reason for terrorist plan: the ship was hijacked
// or there is a terrorist crew member
// Let's assume 50% chance for each
if (Math.random() <= 1 / 2f) {
ship.setHijacked(true);
} else {
ship.setHijacked(false);
assignTerroristCrewMember(ship);
}
// Define the attributes of the ship based on its normal behavior
// for this type of plan.
// The main behaviors present are:
// 1. Bomb a port, which is not the original destination port -> so
// unusual route is likely
// 2. Aggressive behavior
// However, we need to generate data for all attributes, therefore
// we need to call the generate data for all possible behaviors.
generateDataForUnusualRoute(ship);
generateDataForEvasiveBehavior(ship);
generateDataForErraticBehavior(ship);
generateDataForAggressiveBehavior(ship);
}
private void generateDataForUnusualRoute(ShipEntity ship) {
// Define known states for known parents
int hasTypeOfShipState = 0;
int hasExchangeIllicitCargoPartitionState = 0;
int hasBombingPlanState = 0;
if (ship.getShipType() == ShipType.FISHING) {
hasTypeOfShipState = 0;
if (ship.hasTerroristPlan()
&& ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.ExchangeIllicitCargo) {
hasExchangeIllicitCargoPartitionState = 0;
} else {
hasExchangeIllicitCargoPartitionState = 2;
}
} else if (ship.getShipType() == ShipType.MERCHANT) {
hasTypeOfShipState = 1;
if (ship.hasTerroristPlan()
&& ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.ExchangeIllicitCargo) {
hasExchangeIllicitCargoPartitionState = 1;
} else {
hasExchangeIllicitCargoPartitionState = 2;
}
}
if (ship.hasTerroristPlan()
&& ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.BombingPort) {
hasBombingPlanState = 0;
} else {
hasBombingPlanState = 1;
}
// Define if ship is meeting another ship
int areMeetingState = 0;
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("hasExchangeIllicitCargoPartition_ship1");
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("areMeeting_ship1_ship2");
PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
coord[0] = 0;
coord[table.getVariableIndex(parent)] = hasExchangeIllicitCargoPartitionState;
if (Math.random() <= table.getValue(coord))
areMeetingState = 0;
else
areMeetingState = 1;
// Define if ship has a normal change in destination
int hasNormalChangeInDestinationState;
parent = (ProbabilisticNode) pn.getNode("hasTypeOfShip_ship1");
child = (ProbabilisticNode) pn
.getNode("hasNormalChangeInDestination_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
coord[table.getVariableIndex(parent)] = hasTypeOfShipState;
if (Math.random() <= table.getValue(coord)) {
hasNormalChangeInDestinationState = 0;
ship.setHasNormalChangeInDestination(true);
} else {
hasNormalChangeInDestinationState = 1;
ship.setHasNormalChangeInDestination(false);
}
// Define if ship has unusual route
child = (ProbabilisticNode) pn.getNode("hasUnusualRoute_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("areMeeting_ship1_ship2");
coord[table.getVariableIndex(parent)] = areMeetingState;
parent = (ProbabilisticNode) pn.getNode("hasBombingPlan_ship1");
coord[table.getVariableIndex(parent)] = hasBombingPlanState;
parent = (ProbabilisticNode) pn
.getNode("hasNormalChangeInDestination_ship1");
coord[table.getVariableIndex(parent)] = hasNormalChangeInDestinationState;
if (Math.random() <= table.getValue(coord)) {
ship.setOnUnusualRoute(true);
ship.setOnUsualRoute(false);
} else {
ship.setOnUnusualRoute(false);
ship.setOnUsualRoute(true);
}
}
private void generateDataForEvasiveBehavior(ShipEntity ship) {
// Define known states for known parents
int hasExchangeIllicitCargoPartitionState = 0;
if (ship.hasTerroristPlan()
&& ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.ExchangeIllicitCargo) {
if (ship.getShipType() == ShipType.FISHING) {
hasExchangeIllicitCargoPartitionState = 0;
} else if (ship.getShipType() == ShipType.MERCHANT) {
hasExchangeIllicitCargoPartitionState = 1;
} else {
hasExchangeIllicitCargoPartitionState = 2;
}
} else {
hasExchangeIllicitCargoPartitionState = 2;
}
// Define if ship has evasive behavior
int hasEvasiveBehaviorState = 0;
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("hasExchangeIllicitCargoPartition_ship1");
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("hasEvasiveBehavior_ship1");
PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
coord[0] = 0;
coord[table.getVariableIndex(parent)] = hasExchangeIllicitCargoPartitionState;
if (Math.random() <= table.getValue(coord))
hasEvasiveBehaviorState = 0;
else
hasEvasiveBehaviorState = 1;
// Define if ship's electronicis is working
int isElectronicsWorkingState = 0;
child = (ProbabilisticNode) pn.getNode("isElectronicsWorking_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
if (Math.random() <= table.getValue(coord)) {
isElectronicsWorkingState = 0;
ship.setElectronicsWorking(true);
} else {
isElectronicsWorkingState = 1;
ship.setElectronicsWorking(false);
}
// Define if ship has responsive AIS
child = (ProbabilisticNode) pn.getNode("hasResponsiveAIS_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasEvasiveBehavior_ship1");
coord[table.getVariableIndex(parent)] = hasEvasiveBehaviorState;
parent = (ProbabilisticNode) pn.getNode("isElectronicsWorking_ship1");
coord[table.getVariableIndex(parent)] = isElectronicsWorkingState;
if (Math.random() <= table.getValue(coord)) {
ship.setHasResponsiveAIS(true);
} else {
ship.setHasResponsiveAIS(false);
}
// Define if ship has responsive radio
child = (ProbabilisticNode) pn.getNode("hasResponsiveRadio_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasEvasiveBehavior_ship1");
coord[table.getVariableIndex(parent)] = hasEvasiveBehaviorState;
parent = (ProbabilisticNode) pn.getNode("isElectronicsWorking_ship1");
coord[table.getVariableIndex(parent)] = isElectronicsWorkingState;
if (Math.random() <= table.getValue(coord)) {
ship.setHasResponsiveRadio(true);
} else {
ship.setHasResponsiveRadio(false);
}
}
private void generateDataForErraticBehavior(ShipEntity ship) {
// Define known states for known parents
int hasExchangeIllicitCargoPartitionState = 0;
if (ship.hasTerroristPlan()
&& ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.ExchangeIllicitCargo) {
if (ship.getShipType() == ShipType.FISHING) {
hasExchangeIllicitCargoPartitionState = 0;
} else if (ship.getShipType() == ShipType.MERCHANT) {
hasExchangeIllicitCargoPartitionState = 1;
} else {
hasExchangeIllicitCargoPartitionState = 2;
}
} else {
hasExchangeIllicitCargoPartitionState = 2;
}
// Define if ship has erratic behavior
int hasErraticBehaviorState = 0;
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("hasExchangeIllicitCargoPartition_ship1");
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("hasErraticBehavior_ship1");
PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
coord[0] = 0;
coord[table.getVariableIndex(parent)] = hasExchangeIllicitCargoPartitionState;
if (Math.random() <= table.getValue(coord))
hasErraticBehaviorState = 0;
else
hasErraticBehaviorState = 1;
// Define if ship has equipment failure
int hasEquipmentFailureState = 0;
child = (ProbabilisticNode) pn.getNode("hasEquipmentFailure_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
if (Math.random() <= table.getValue(coord)) {
hasEquipmentFailureState = 0;
ship.setHasEquipmentFailure(true);
} else {
hasEquipmentFailureState = 1;
ship.setHasEquipmentFailure(false);
}
// Define if ship has crew visible
child = (ProbabilisticNode) pn.getNode("isCrewVisible_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasErraticBehavior_ship1");
coord[table.getVariableIndex(parent)] = hasErraticBehaviorState;
parent = (ProbabilisticNode) pn.getNode("hasEquipmentFailure_ship1");
coord[table.getVariableIndex(parent)] = hasEquipmentFailureState;
if (Math.random() <= table.getValue(coord)) {
ship.setCrewVisible(true);
} else {
ship.setCrewVisible(false);
}
}
private void generateDataForAggressiveBehavior(ShipEntity ship) {
// Define known states for known parents
int hasExchangeIllicitCargoPartitionState = 0;
int hasBombingPlanState = 0;
if (ship.hasTerroristPlan()
&& ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.ExchangeIllicitCargo) {
if (ship.getShipType() == ShipType.FISHING) {
hasExchangeIllicitCargoPartitionState = 0;
} else if (ship.getShipType() == ShipType.MERCHANT) {
hasExchangeIllicitCargoPartitionState = 1;
} else {
hasExchangeIllicitCargoPartitionState = 2;
}
} else {
hasExchangeIllicitCargoPartitionState = 2;
}
if (ship.hasTerroristPlan()
&& ship.getTerroristPlan().getTerroristPlanType() == TerroristPlanType.BombingPort) {
hasBombingPlanState = 0;
} else {
hasBombingPlanState = 1;
}
// Define if ship has aggressive behavior
int hasAggressiveBehaviorState = 0;
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("hasAggressiveBehavior_ship1");
PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
coord[0] = 0;
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("hasExchangeIllicitCargoPartition_ship1");
coord[table.getVariableIndex(parent)] = hasExchangeIllicitCargoPartitionState;
parent = (ProbabilisticNode) pn.getNode("hasBombingPlan_ship1");
coord[table.getVariableIndex(parent)] = hasBombingPlanState;
float f = table.getValue(coord);
if (Math.random() <= f){
ship.setHasAggressiveBehaviorState(true);
hasAggressiveBehaviorState = 0;
}
else{
ship.setHasAggressiveBehaviorState(false);
hasAggressiveBehaviorState = 1;
}
// Define if ship weapon visible
child = (ProbabilisticNode) pn.getNode("hasWeaponVisible_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasAggressiveBehavior_ship1");
coord[table.getVariableIndex(parent)] = hasAggressiveBehaviorState;
if (Math.random() <= table.getValue(coord)) {
ship.setHasWeaponVisible(true);
} else {
ship.setHasWeaponVisible(false);
}
// Define if ship is jettisoning cargo
child = (ProbabilisticNode) pn.getNode("isJettisoningCargo_ship1");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasAggressiveBehavior_ship1");
coord[table.getVariableIndex(parent)] = hasAggressiveBehaviorState;
if (Math.random() <= table.getValue(coord)) {
ship.setJettisoningCargo(true);
} else {
ship.setJettisoningCargo(false);
}
}
/**
* Assign a random crew member as a terrorist for the given ship.
*
* @param ship
* The ship that must have a random crew member selected as a
* terrorist.
*/
private void assignTerroristCrewMember(ShipEntity ship) {
int rand = getRandom(0, ship.getCrew().size() - 1);
ship.getCrew().get(rand).setTerrorist(true);
}
public void generateDataForCommunication(PersonEntity person) {
// Define known states for known parents
int isTerroristState = (person.isTerrorist()) ? 0 : 1;
// Define if person communicates with terrorist
int communicatesWithTerroristsState = 0;
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("communicatesWithTerrorists_person");
PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
coord[0] = 0;
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("isTerrorist_person");
coord[table.getVariableIndex(parent)] = isTerroristState;
if (Math.random() <= table.getValue(coord)) {
communicatesWithTerroristsState = 0;
person.setCommunicatesWithTerrorists(true);
} else {
communicatesWithTerroristsState = 1;
person.setCommunicatesWithTerrorists(false);
}
// Define if person uses weblog
child = (ProbabilisticNode) pn.getNode("usesWeblog_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("communicatesWithTerrorists_person");
coord[table.getVariableIndex(parent)] = communicatesWithTerroristsState;
if (Math.random() <= table.getValue(coord)) {
person.setUsesWeblog(true);
} else {
person.setUsesWeblog(false);
}
// Define if person uses email
child = (ProbabilisticNode) pn.getNode("usesEmail_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
coord[table.getVariableIndex(parent)] = communicatesWithTerroristsState;
if (Math.random() <= table.getValue(coord)) {
person.setUsesEmail(true);
} else {
person.setUsesEmail(false);
}
// Define if person uses cellular
child = (ProbabilisticNode) pn.getNode("usesCellular_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
coord[table.getVariableIndex(parent)] = communicatesWithTerroristsState;
if (Math.random() <= table.getValue(coord)) {
person.setUsesCellular(true);
} else {
person.setUsesCellular(false);
}
// Define if person uses chatroom
child = (ProbabilisticNode) pn.getNode("usesChatroom_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
coord[table.getVariableIndex(parent)] = communicatesWithTerroristsState;
if (Math.random() <= table.getValue(coord)) {
person.setUsesChatroom(true);
} else {
person.setUsesChatroom(false);
}
}
public void generateDataForRelationship(PersonEntity person) {
// Define known states for known parents
int isTerroristState = (person.isTerrorist()) ? 0 : 1;
// Define if person has terrorist beliefs
int hasTerroristBeliefsState = 0;
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("hasTerroristBeliefs_person");
PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
coord[0] = 0;
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("isTerrorist_person");
coord[table.getVariableIndex(parent)] = isTerroristState;
if (Math.random() <= table.getValue(coord)) {
hasTerroristBeliefsState = 0;
person.setCommunicatesWithTerrorists(true);
} else {
hasTerroristBeliefsState = 1;
person.setCommunicatesWithTerrorists(false);
}
// Define if person has kinship to terrorist (none, few, or many)
child = (ProbabilisticNode) pn.getNode("hasKinshipToTerrorist_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasTerroristBeliefs_person");
coord[table.getVariableIndex(parent)] = hasTerroristBeliefsState;
float noneUpperBound = table.getValue(coord);
coord[0] = 1;
float fewUpperBound = noneUpperBound + table.getValue(coord);
float randomProbability = (float) Math.random();
if (randomProbability <= noneUpperBound) {
person.setHasKinshipToTerrorist(Quantity.None);
} else if (randomProbability <= fewUpperBound) {
person.setHasKinshipToTerrorist(Quantity.Few);
} else {
person.setHasKinshipToTerrorist(Quantity.Many);
}
// Define if person has friendship with terrorist (none, few, or many)
child = (ProbabilisticNode) pn.getNode("hasFriendshipWithTerrorist_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasTerroristBeliefs_person");
coord[table.getVariableIndex(parent)] = hasTerroristBeliefsState;
noneUpperBound = table.getValue(coord);
coord[0] = 1;
fewUpperBound = noneUpperBound + table.getValue(coord);
randomProbability = (float) Math.random();
if (randomProbability <= noneUpperBound) {
person.setHasFriendshipWithTerrorist(Quantity.None);
} else if (randomProbability <= fewUpperBound) {
person.setHasFriendshipWithTerrorist(Quantity.Few);
} else {
person.setHasFriendshipWithTerrorist(Quantity.Many);
}
}
public void generateDataForAssociation(PersonEntity person) {
// Define known states for known parents
int isTerroristState = (person.isTerrorist()) ? 0 : 1;
// Define the cluster partition of a person (CentralStaff, SoutheastAsia,
// MaghrebArab, CoreArab, or Other)
int hasClusterPartitionState = 0;
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("hasClusterPartition_person");
PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("isTerrorist_person");
coord[table.getVariableIndex(parent)] = isTerroristState;
coord[0] = 0;
float centralStaffUpperBound = table.getValue(coord);
coord[0] = 1;
float southeastAsiaUpperBound = centralStaffUpperBound + table.getValue(coord);
coord[0] = 2;
float maghrebArabUpperBound = southeastAsiaUpperBound + table.getValue(coord);
coord[0] = 3;
float coreArabUpperBound = maghrebArabUpperBound + table.getValue(coord);
float randomProbability = (float) Math.random();
if (randomProbability <= centralStaffUpperBound) {
hasClusterPartitionState = 0;
person.setHasClusterPartition(ClusterPartition.CentralStaff);
} else if (randomProbability <= southeastAsiaUpperBound) {
hasClusterPartitionState = 1;
person.setHasClusterPartition(ClusterPartition.SoutheastAsia);
} else if (randomProbability <= maghrebArabUpperBound) {
hasClusterPartitionState = 2;
person.setHasClusterPartition(ClusterPartition.MaghrebArab);
} else if (randomProbability <= coreArabUpperBound) {
hasClusterPartitionState = 3;
person.setHasClusterPartition(ClusterPartition.CoreArab);
} else {
hasClusterPartitionState = 4;
person.setHasClusterPartition(ClusterPartition.Other);
}
// Define the person nationality (Egypt, SaudiArabia, etc)
child = (ProbabilisticNode) pn.getNode("hasNationality_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
parent = (ProbabilisticNode) pn.getNode("hasClusterPartition_person");
coord[table.getVariableIndex(parent)] = hasClusterPartitionState;
coord[0] = 0;
float egyptUpperBound = table.getValue(coord);
coord[0] = 1;
float saudiArabiaUpperBound = egyptUpperBound + table.getValue(coord);
coord[0] = 2;
float kuwaitUpperBound = saudiArabiaUpperBound + table.getValue(coord);
coord[0] = 3;
float jordanUpperBound = kuwaitUpperBound + table.getValue(coord);
coord[0] = 4;
float iraqUpperBound = jordanUpperBound + table.getValue(coord);
coord[0] = 5;
float sudanUpperBound = iraqUpperBound + table.getValue(coord);
coord[0] = 6;
float libyaUpperBound = sudanUpperBound + table.getValue(coord);
coord[0] = 7;
float lebannonUpperBound = libyaUpperBound + table.getValue(coord);
coord[0] = 8;
float indonesiaUpperBound = lebannonUpperBound + table.getValue(coord);
coord[0] = 9;
float malaysiaUpperBound = indonesiaUpperBound + table.getValue(coord);
coord[0] = 10;
float singaporeUpperBound = malaysiaUpperBound + table.getValue(coord);
coord[0] = 11;
float pakistanUpperBound = singaporeUpperBound + table.getValue(coord);
coord[0] = 12;
float philippinesUpperBound = pakistanUpperBound + table.getValue(coord);
coord[0] = 13;
float franceUpperBound = philippinesUpperBound + table.getValue(coord);
coord[0] = 14;
float algeriaUpperBound = franceUpperBound + table.getValue(coord);
coord[0] = 15;
float moroccoUpperBound = algeriaUpperBound + table.getValue(coord);
coord[0] = 16;
float syriaUpperBound = moroccoUpperBound + table.getValue(coord);
coord[0] = 17;
float tunisiaUpperBound = syriaUpperBound + table.getValue(coord);
coord[0] = 18;
float uaeUpperBound = tunisiaUpperBound + table.getValue(coord);
coord[0] = 19;
float yemenUpperBound = uaeUpperBound + table.getValue(coord);
randomProbability = (float) Math.random();
if (randomProbability <= egyptUpperBound) {
person.setHasNationality(Nationality.Egypt);
} else if (randomProbability <= saudiArabiaUpperBound) {
person.setHasNationality(Nationality.SaudiArabia);
} else if (randomProbability <= kuwaitUpperBound) {
person.setHasNationality(Nationality.Kuwait);
} else if (randomProbability <= jordanUpperBound) {
person.setHasNationality(Nationality.Jordan);
} else if (randomProbability <= iraqUpperBound) {
person.setHasNationality(Nationality.Iraq);
} else if (randomProbability <= sudanUpperBound) {
person.setHasNationality(Nationality.Sudan);
} else if (randomProbability <= libyaUpperBound) {
person.setHasNationality(Nationality.Libya);
} else if (randomProbability <= lebannonUpperBound) {
person.setHasNationality(Nationality.Lebannon);
} else if (randomProbability <= indonesiaUpperBound) {
person.setHasNationality(Nationality.Indonesia);
} else if (randomProbability <= malaysiaUpperBound) {
person.setHasNationality(Nationality.Malaysia);
} else if (randomProbability <= singaporeUpperBound) {
person.setHasNationality(Nationality.Singapore);
} else if (randomProbability <= pakistanUpperBound) {
person.setHasNationality(Nationality.Pakistan);
} else if (randomProbability <= philippinesUpperBound) {
person.setHasNationality(Nationality.Philippines);
} else if (randomProbability <= franceUpperBound) {
person.setHasNationality(Nationality.France);
} else if (randomProbability <= algeriaUpperBound) {
person.setHasNationality(Nationality.Algeria);
} else if (randomProbability <= moroccoUpperBound) {
person.setHasNationality(Nationality.Morocco);
} else if (randomProbability <= syriaUpperBound) {
person.setHasNationality(Nationality.Syria);
} else if (randomProbability <= tunisiaUpperBound) {
person.setHasNationality(Nationality.Tunisia);
} else if (randomProbability <= uaeUpperBound) {
person.setHasNationality(Nationality.UAE);
} else if (randomProbability <= yemenUpperBound) {
person.setHasNationality(Nationality.Yemen);
} else {
person.setHasNationality(Nationality.Other);
}
// Define the person economic standing (UpperClass, MiddleClass, or
// LowerClass)
child = (ProbabilisticNode) pn.getNode("hasEconomicStanding_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
parent = (ProbabilisticNode) pn.getNode("hasClusterPartition_person");
coord[table.getVariableIndex(parent)] = hasClusterPartitionState;
coord[0] = 0;
float upperClassUpperBound = table.getValue(coord);
coord[0] = 1;
float middleClassUpperBound = upperClassUpperBound + table.getValue(coord);
randomProbability = (float) Math.random();
if (randomProbability <= upperClassUpperBound) {
person.setHasEconomicStanding(EconomicStanding.UpperClass);
} else if (randomProbability <= middleClassUpperBound) {
person.setHasEconomicStanding(EconomicStanding.MiddleClass);
} else {
person.setHasEconomicStanding(EconomicStanding.LowerClass);
}
// Define the person education level (MiddleSchool, HighSchool, College,
// BA_BS, MA_MS, or PhD)
child = (ProbabilisticNode) pn.getNode("hasEducationLevel_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
parent = (ProbabilisticNode) pn.getNode("hasClusterPartition_person");
coord[table.getVariableIndex(parent)] = hasClusterPartitionState;
coord[0] = 0;
float middleSchoolUpperBound = table.getValue(coord);
coord[0] = 1;
float highSchoolUpperBound = middleSchoolUpperBound + table.getValue(coord);
coord[0] = 2;
float collegeUpperBound = highSchoolUpperBound + table.getValue(coord);
coord[0] = 3;
float baBsUpperBound = collegeUpperBound + table.getValue(coord);
coord[0] = 4;
float maMsUpperBound = baBsUpperBound + table.getValue(coord);
randomProbability = (float) Math.random();
if (randomProbability <= middleSchoolUpperBound) {
person.setHasEducationLevel(EducationLevel.MiddleSchool);
} else if (randomProbability <= highSchoolUpperBound) {
person.setHasEducationLevel(EducationLevel.HighSchool);
} else if (randomProbability <= collegeUpperBound) {
person.setHasEducationLevel(EducationLevel.College);
} else if (randomProbability <= baBsUpperBound) {
person.setHasEducationLevel(EducationLevel.BA_BS);
} else if (randomProbability <= maMsUpperBound) {
person.setHasEducationLevel(EducationLevel.MA_MS);
} else {
person.setHasEducationLevel(EducationLevel.PhD);
}
// Define the person occupation (Professional, SemiSkilled, or UnSkilled)
child = (ProbabilisticNode) pn.getNode("hasOccupation_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
parent = (ProbabilisticNode) pn.getNode("hasClusterPartition_person");
coord[table.getVariableIndex(parent)] = hasClusterPartitionState;
coord[0] = 0;
float professionalUpperBound = table.getValue(coord);
coord[0] = 1;
float semiSkilledUpperBound = professionalUpperBound + table.getValue(coord);
randomProbability = (float) Math.random();
if (randomProbability <= professionalUpperBound) {
person.setHasOccupation(Occupation.Professional);
} else if (randomProbability <= semiSkilledUpperBound) {
person.setHasOccupation(Occupation.SemiSkilled);
} else {
person.setHasOccupation(Occupation.UnSkilled);
}
}
public void generateDataForBackground(PersonEntity person) {
// Define known states for known parents
int isTerroristState = (person.isTerrorist()) ? 0 : 1;
// Define if person has influence partition
int hasInfluencePartitionState = 0;
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("hasInfluencePartition_person");
PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
coord[0] = 0;
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("isTerrorist_person");
coord[table.getVariableIndex(parent)] = isTerroristState;
if (Math.random() <= table.getValue(coord)) {
hasInfluencePartitionState = 0;
person.setHasInfluencePartition(true);
} else {
hasInfluencePartitionState = 1;
person.setHasInfluencePartition(false);
}
// Define the person family status
child = (ProbabilisticNode) pn
.getNode("hasFamilyStatus_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn
.getNode("hasInfluencePartition_person");
coord[table.getVariableIndex(parent)] = hasInfluencePartitionState;
if (Math.random() <= table.getValue(coord)) {
person.setHasFamilyStatus(FamilyStatus.Married);
} else {
person.setHasFamilyStatus(FamilyStatus.Single);
}
// Define if person has OIF or OEF influence
int hasOIForOEFInfluenceState = 0;
child = (ProbabilisticNode) pn
.getNode("hasOIForOEFInfluence_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn
.getNode("hasInfluencePartition_person");
coord[table.getVariableIndex(parent)] = hasInfluencePartitionState;
if (Math.random() <= table.getValue(coord)) {
hasOIForOEFInfluenceState = 0;
person.setHasOIForOEFInfluence(true);
} else {
hasOIForOEFInfluenceState = 1;
person.setHasOIForOEFInfluence(false);
}
// Define if person someone kileld in OIF or OEF (none, few, or many)
child = (ProbabilisticNode) pn.getNode("knowsPersonKilledInOIForOEF_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasOIForOEFInfluence_person");
coord[table.getVariableIndex(parent)] = hasOIForOEFInfluenceState;
float noneUpperBound = table.getValue(coord);
coord[0] = 1;
float fewUpperBound = noneUpperBound + table.getValue(coord);
float randomProbability = (float) Math.random();
if (randomProbability <= noneUpperBound) {
person.setKnowsPersonKilledinOIForOEF(Quantity.None);
} else if (randomProbability <= fewUpperBound) {
person.setKnowsPersonKilledinOIForOEF(Quantity.Few);
} else {
person.setKnowsPersonKilledinOIForOEF(Quantity.Many);
}
// Define if person someone imprisioned in OIF or OEF (none, few, or many)
child = (ProbabilisticNode) pn.getNode("knowsPersonImprisionedInOIForOEF_person");
table = ((PotentialTable) child.getProbabilityFunction());
coord = new int[child.getParents().size() + 1];
coord[0] = 0;
parent = (ProbabilisticNode) pn.getNode("hasOIForOEFInfluence_person");
coord[table.getVariableIndex(parent)] = hasOIForOEFInfluenceState;
noneUpperBound = table.getValue(coord);
coord[0] = 1;
fewUpperBound = noneUpperBound + table.getValue(coord);
randomProbability = (float) Math.random();
if (randomProbability <= noneUpperBound) {
person.setKnowsPersonImprisionedInOIForOEF(Quantity.None);
} else if (randomProbability <= fewUpperBound) {
person.setKnowsPersonImprisionedInOIForOEF(Quantity.Few);
} else {
person.setKnowsPersonImprisionedInOIForOEF(Quantity.Many);
}
}
/**
* Use Bayesian Network to decide values for entity attributes
*/
private void populateEntities(int nTrials) {
for (int j = 0; j < nTrials; j++) {
for (int i = 0; i < nTerroristPlans; i++) {
// We need to decide what is the type of terrorist plan
// Let's assume exchange illicit cargo is twice more likely than
// bombing a port
if (Math.random() <= 2 / 3f) {
generateExchangeIllicitCargoPlan(new ExchangeIllicitCargoPlan());
} else {
generateBombingPortPlan(new BombingPortPlan());
}
}
// Simulate data for non-naval ships without terrorist plan
for (ShipEntity ship : db.getShips()) {
// No need to simulate data for these ships
if (ship.getShipType() == ShipType.NAVAL
|| ship.hasTerroristPlan()) {
continue;
}
// Define the attributes of the ship based on its normal
// behavior
// given it has no terrorist paln
// The main behaviors are:
// 1. Will not present an unusual route
// 2. Will not present an evasive behavior
// 3. Will not present an erratic behavior
// 4. Will not present an aggressive behavior
// However, we need to generate data for all attributes,
// therefore
// we need to call the generate data for all possible behaviors.
generateDataForUnusualRoute(ship);
generateDataForEvasiveBehavior(ship);
generateDataForErraticBehavior(ship);
generateDataForAggressiveBehavior(ship);
}
// Young added
// Define continuous and discretized values for aggressive behavior
GenerateDataForChildrenOfAggressiveBehavior gdc = new GenerateDataForChildrenOfAggressiveBehavior();
gdc.fillInformation(db.getShips());
// Simulate person data
for (PersonEntity person : db.getPeople()) {
// Generate communication data
generateDataForCommunication(person);
// Generate relationship data
generateDataForRelationship(person);
// Generate socio-economic data (based on group association)
generateDataForAssociation(person);
// Generate background influence data
generateDataForBackground(person);
}
// Simulate organization data
for (OrganizationEntity org : db.getOrganizations()) {
ProbabilisticNode child = (ProbabilisticNode) pn
.getNode("isTerroristOrganization_org");
PotentialTable table = ((PotentialTable) child
.getProbabilityFunction());
int[] coord = new int[child.getParents().size() + 1];
coord[0] = 0;
ProbabilisticNode parent = (ProbabilisticNode) pn
.getNode("isTerrorist_person");
// True if at least one member is a terrorist
coord[table.getVariableIndex(parent)] = (org.isRelatedToTerrorist()) ? 0
: 1;
parent = (ProbabilisticNode) pn
.getNode("isMemberOfOrganization_person_org");
// Always true, since we are dealing with members of the organization
coord[table.getVariableIndex(parent)] = 0;
if (Math.random() <= table.getValue(coord)) {
org.setTerroristOrganisation(true);
} else
org.setTerroristOrganisation(false);
}
}
}
private void generateOrganizations(int num) {
for (int i = 0; i < num; i++) {
db.addOrganization(new OrganizationEntity(i));
}
}
private void generateShips() {
for (int i = 0; i < nShips; i++) {
ShipEntity ship = new ShipEntity(i);
if (i < nNavalShips) {
ship.setShipType(ShipType.NAVAL);
} else if (i < nNavalShips + nFishingShips) {
ship.setShipType(ShipType.FISHING);
} else {
ship.setShipType(ShipType.MERCHANT);
}
db.addShip(ship);
}
}
private void generatePeople() {
for (int i = 0; i < nPeople; i++) {
db.addPerson(new PersonEntity(i));
}
}
/**
* randomly associate relations to people
*/
public void generateSocialNetwork() {
for (PersonEntity pe : db.getPeople()) {
// currently 2 levels of relationships, choose people each, then 5
// from each of them
addRandomRelation(pe, 2);
}
}
/**
* Random numbers between a range
*/
public int getRandom(int min, int max) {
return (int) (Math.random() * (max - min + 1)) + min;
}
/**
* Recursive method to add relations
*
* @param person
* @param level
*/
private void addRandomRelation(PersonEntity person, int levels) {
if (levels > 0) {
for (int i = 0; i < 5; i++) {
int rand = getRandom(0, nPeople - 1);
person.addIsRelatedTo(db.getPeople().get(rand));
db.getPeople().get(rand).addIsRelatedTo(person);
addRandomRelation(db.getPeople().get(rand), levels - 1);
}
}
}
/**
* randomly associate organizations to people
*/
public void associateOrganizations() {
// create nPeople / 2 memberOf associations
for (int i = 0; i < nPeople / 2; i++) {
int rand1 = getRandom(0, nPeople - 1);
PersonEntity person = db.getPeople().get(rand1);
int rand2 = getRandom(0, nOrganizations - 1);
OrganizationEntity organization = db.getOrganizations().get(rand2);
while (organization.getMembers().contains(person)) {
rand1 = getRandom(0, nPeople - 1);
person = db.getPeople().get(rand1);
}
organization.addMember(person);
person.addRelatedOrganization(organization);
}
}
/**
* print out GT data
*/
public void printGroundTruthData() {
for (PersonEntity pe : db.getPeople()) {
System.out.println("Person " + db.getPeople().indexOf(pe)
+ " is a terrorist = " + pe.isTerrorist());
}
for (ShipEntity se : db.getShips()) {
System.out.println("Ship " + db.getShips().indexOf(se)
+ " is SOI = " + se.isShipOfInterest());
}
for (OrganizationEntity org : db.getOrganizations()) {
System.out.println("Organisation "
+ db.getOrganizations().indexOf(org)
+ " is a terrorist org = " + org.isTerroristOrganisation());
}
}
/**
* When TDB is updated, this function is called
*/
public void onUpdated(Object o) {
if( o instanceof String ){
if(((String)o).equalsIgnoreCase("SimulationFinishied"))
System.out.println("Simulation Finishied");
}
Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
for (Unit ship : ships.list) {
int id = ships.list.indexOf(ship);
ShipEntity shipEntity = db.getShips().get(id);
String strRoute = ship.get("Route").getData();
String strMeeting = ship.get("Meeting").getData();
if( strRoute.equalsIgnoreCase("Unusual")){
shipEntity.setOnUnusualRoute(true);
shipEntity.setOnUsualRoute(false);
}else
if( strRoute.equalsIgnoreCase("Usual")){
shipEntity.setOnUnusualRoute(false);
shipEntity.setOnUsualRoute(true);
}
if( !strMeeting.equalsIgnoreCase("none")){
//do something with shipEntity
//EX) strMeeting = ship1 and a current ship is ship0
ArrayList<ShipEntity> possibleMeeting = shipEntity.getPossibleMeeting();
int idMeeting = ships.list.indexOf(strMeeting);
ShipEntity shipEntityMet = db.getShips().get(id);
if(!possibleMeeting.contains(shipEntityMet)){
possibleMeeting.add(shipEntityMet);
}
}
}
}
}