Package trackerModule.core.datastructure

Examples of trackerModule.core.datastructure.Unit


  // create rule for Illicit Cargo Ship
  /**
   * Creates the rules for illicit cargo ship.
   */
  void createRulesForIllicitCargoShip(){
    Unit ship      = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+getName());
    Unit location    = ship.get("Location");
    Unit destination  = ship.get("Destination");
    Unit IllicitCargoPlanShip  = ship.get("IllicitCargoPlan_Ship");
    Unit IllicitCargoPlanArea  = ship.get("IllicitCargoPlan_Area");
    Unit ship2      = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+IllicitCargoPlanShip.getData());
    Unit IllicitCargoPlanArea2  = ship2.get("IllicitCargoPlan_Area");
    Unit location2  = ship2.get("Location");
    String strMeeting  = IllicitCargoPlanArea2.getData();
    if( IllicitCargoPlanArea.getData().equalsIgnoreCase("none") &&
      IllicitCargoPlanArea2.getData().equalsIgnoreCase("none") ){
      strMeeting  = World.This().getUnusualAreaBetween( location.getData(), location2.getData() );
     
      IllicitCargoPlanArea.setData(strMeeting);
      IllicitCargoPlanArea2.setData(strMeeting);
    }
   
View Full Code Here


   * Check condition.
   *
   * @param ru the rule unit
   */
  public void checkCondition(Rule_Unit ru) {
    Unit ship      = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+ru.getOwnerName());
    Unit state      = ship.get("State");
    Unit stateTime    = ship.get("StateTime");
    Unit stateTimeCount  = ship.get("StateTimeCount");

    for( String str : ru.getCondition().keySet() ){
      Object[] ob = ru.getCondition().get(str);
      
      if( str.equalsIgnoreCase("IsGlobalTime")){
        if( RDB.This().getTime() != (Integer)ob[0] )
          return;
      }else
      if( str.equalsIgnoreCase("IsState") ){
        if( !ob[0].equals(state.getData()) )
          return;
      }else
      if( str.equalsIgnoreCase("TimeFinished") ){
        //System.out.println(stateTime.getData() + ": " + stateTimeCount.getData());
        if( !stateTime.getData().equals(stateTimeCount.getData()) )
          return;
      }else
      if( str.equalsIgnoreCase("NotTimeFinished") ){
         if( stateTime.getData().equals(stateTimeCount.getData()) )
          return;
      }else
      if( str.equalsIgnoreCase("InArea") ){
        if( !isIn(ru.getOwnerName(), (Double)ob[0], (Double)ob[1] ) )
          return;
View Full Code Here

   * Check action.
   *
   * @param ru the rule unit
   */
  public void checkAction(Rule_Unit ru) {
    Unit ship      = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+ru.getOwnerName());
    Unit state      = ship.get("State");
    Unit stateTime    = ship.get("StateTime");
    Unit stateTimeCount  = ship.get("StateTimeCount");
    Double rand  = Math.random();
   
    Action ac = ru.inProbability(rand);
    for( String str : ac.getActionMap().keySet() ){
      Object[] ob = ac.getActionMap().get(str);
           
      if( str.equalsIgnoreCase("SetState") ){
      //  System.out.println(ru.getOwnerName() + ": " + str + ": " + ob[0]);
        state.setData(ob[0]);       
        if( ob.length >= 2 ){
          stateTime.setData(ob[1]);
          stateTimeCount.setData(0);
        }
      }else
      if( str.equalsIgnoreCase("MoveTo") ){
        moveToDestination( ru.getOwnerName(), (Double)ob[0], (Double)ob[1] );
      }else
      if( str.equalsIgnoreCase("Wandering") ){
        wandering(ru.getOwnerName());
      }else
      if( str.equalsIgnoreCase("Waiting") ){
      }else
      if( str.equalsIgnoreCase("Contacting") ){
        Unit anotherShip = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+(String)ob[0]);
        moveToDestination( ru.getOwnerName(), anotherShip.get("X").getDataByDouble(), anotherShip.get("Y").getDataByDouble() );
      }
    }       
  }  
View Full Code Here

    else
    if( !ru.getName().equalsIgnoreCase("RDBROOT") &&
      !ru.getName().equalsIgnoreCase("SHIP_RULE") ){
     
      //count state time
      Unit ship      = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+ru.getName());
      Unit stateTimeCount  = ship.get("StateTimeCount");
      stateTimeCount.setData(stateTimeCount.getDataByInt()+1);
    //  stateTimeCount.print("");
    }
  }  
View Full Code Here

   * @return the destination
   */
  public String getDestination(){
    String str = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+strName + ".Destination").getData();
    String strLoc = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+strName + ".Location").getData();
    Unit uSize = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+strName + ".Size");
       
    if( str == null ){
      String strType = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS."+strName + ".Type").getData();
     
      if( strType.equals("MerchantShip") ){
       
        str = World.This().getRandomBigPortWithMerchantArea(strLoc);
               
        Double r = Math.random();
               
        String newSize = "";
        if(isMerchantArea(str)){
          if( r < 0.6)
            newSize = "Big";
           else
            newSize = "Small"
        }else{
          if( r < 0.3)
            newSize = "Big";
           else
            newSize = "Small"
        }
        
        uSize.setData(0, newSize);
      }else
      if( strType.equals("IllicitCargoMerchantShip") ||
        strType.equals("BombingMerchantShip") ){
         
        str = World.This().getRandomBigPort(strLoc);
                 
        Double r = Math.random();
                 
        String newSize = "";
        if(isMerchantArea(str)){
          if( r < 0.6)
            newSize = "Big";
           else
            newSize = "Small"
        }else{
          if( r < 0.3)
            newSize = "Big";
           else
            newSize = "Small"
        }
          
        uSize.setData(0, newSize);
      }else
      if( strType.equals("IllicitCargoFishingShip") ||
        strType.equals("FishingShip") ||
        strType.equals("BombingFishingShip")){
         str = World.This().getRandomSmallPort(strLoc);
View Full Code Here

   * Draw selected ship circle.
   *
   * @param g the Graphics
   */
  private void drawSelectedShipCircle(Graphics g) {
    Unit s = frame.getCurEntity();
   
    if(s != null){
      String strState = s.get("State").getData();
      if( strState.indexOf("waiting") >=0 || strState.equalsIgnoreCase("end"))
        return;
     
      Graphics2D g2 = (Graphics2D) g;  
      Integer x = s.get("X").getDataByInt();
      Integer y = s.get("Y").getDataByInt();
      int iDiameter = World.This().getDetectingMileForScreen();
     
          Stroke oldStroke = g2.getStroke();
      g2.setColor(new Color(10,10,255,100));
      g2.setStroke(dashedStroke);  
View Full Code Here

  //////////////////////////////////////////////////////////////////////////////////////////////////////
  /* (non-Javadoc)
   * @see trackerModule.core.rulestructure.IMessageObject#onUpdated(java.lang.Object)
   */
  public void onUpdated(Object o) {
    Unit ships = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS");
   
    for( Unit ship : ships.getList() ){
        updateShipGEntityOnCanvas(ship);
    }
   
    Rectangle r = this.getVisibleRect();
    repaint((int)r.getX(), (int)r.getY(), (int)r.getWidth(), (int)r.getHeight());
View Full Code Here

    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();
View Full Code Here

   * Wandering.
   *
   * @param strName the name
   */
  public void wandering(String strName){
    Unit ship    = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS." + strName);
    Unit location  = ship.get("Location");
   
    Double X    = ship.get("X").getDataByDouble();
    Double Y    = ship.get("Y").getDataByDouble();
        
    //new position
    double xNew = X;
    double yNew = Y; 
   
    if(Math.random() > 0.5)
      xNew += (int)(Math.random());
    else
      xNew -= (int)(Math.random());
   
    if(Math.random() > 0.5)
      yNew += (int)(Math.random());
    else
      yNew -= (int)(Math.random());
       
    //Put new position of this ship
    ship.get("X").setData(xNew);
    ship.get("Y").setData(yNew);
   
    ship.get("Longitude").setData(getLongitudeByX(xNew));
    ship.get("Latitude").setData(getLatitudeByY(yNew));
    ship.get("Speed").setData(0.0);
   
   
    location.setData(getCurrentLocation( ship ));
 
View Full Code Here

   * @param strName the name
   * @param desX the destination x
   * @param desY the destination y
   */
  public void moveToDestination( String strName,  Double desX, Double desY  ){
    Unit ship    = TDB.This().get("TDBROOT.MODEL.WORLD.SHIPS." + strName);
    Unit location  = ship.get("Location");
    Double X    = ship.get("X").getDataByDouble();
    Double Y    = ship.get("Y").getDataByDouble();
       
     //random velocity
    //             1 knot : 1.8532 km  : 6.85684 dot
    //   0.539607166 knot :      1 km  :     3.7 dot
    //            10 knot : 18.532 km  : 68.5684 dot :          60 min
    //                                         1 dot : 0.875038648 min
    //                               1.142806667 dot :           1 min
    //
    //1 knot = 1 nautical mile per hour = 6076 feet per hour
    //1 mph =1 mile per hour = 5280 feet per hour
   
    Double randomKnot = 10 + ((Math.random()*1)*((Math.random() < .5d)?-1:1));
   
    // TODO change this portion if the speed is important for estimating ship type or identifying terrorists
    // change the speed by type of ship
//    Unit type = ship.get("Type");
//    if(type.getData().equalsIgnoreCase("BombingFishingShip")
//        || type.getData().equalsIgnoreCase("BombingMerchantShip")
//        || type.getData().equalsIgnoreCase("IllicitCargoMerchantShip")
//        || type.getData().equalsIgnoreCase("IllicitCargoFishingShip")) {
//      //
//      randomKnot = 15 + ((Math.random()*5)*((Math.random() < .5d)?-1:1));
//    }
   
    Double dotSpeed = getDotByKnot(randomKnot);
    //get new position based on move size 
    double[] newPos = getNewPosition(dotSpeed, X, Y, desX, desY);

    //new position
    double xNew = X + newPos[0];
    double yNew = Y + newPos[1];
           
    //3. Put new position of this ship
    ship.get("X").setData(xNew);
    ship.get("Y").setData(yNew);
    
    ship.get("Longitude").setData(getLongitudeByX(xNew));
    ship.get("Latitude").setData(getLatitudeByY(yNew));
    ship.get("Speed").setData(randomKnot);
   
    //find current location
  //  location.setData("A");
    location.setData(getCurrentLocation( ship ));
    //System.out.println(strName + ": x: " + xNew +"y: " + yNew);
  }
View Full Code Here

TOP

Related Classes of trackerModule.core.datastructure.Unit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.