Exemple #1
0
  /*
  shipment_route
  shipment1 10
  shipment2 15
  pick1_pick2_deliver2_deliver1

   */
  @Test
  public void when_shipmentroute_loadAtEndShouldBe0() {
    stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
    Capacity routeState =
        stateManager.getRouteState(shipment_route, InternalStates.LOAD_AT_END, Capacity.class);
    assertEquals(0, routeState.get(0));
  }
  @Test
  public void testAssignmentClearedOnError() throws Exception {
    expect(offerManager.getOffers(GROUP_KEY)).andReturn(ImmutableSet.of(OFFER));
    offerManager.launchTask(MESOS_OFFER.getId(), TASK_INFO);
    expectLastCall().andThrow(new OfferManager.LaunchException("expected"));
    expect(tierManager.getTier(TASK.getAssignedTask().getTask())).andReturn(DEFAULT);
    expect(filter.filter(UNUSED, RESOURCE_REQUEST)).andReturn(ImmutableSet.of());
    expect(
            stateManager.assignTask(
                storeProvider,
                Tasks.id(TASK),
                MESOS_OFFER.getHostname(),
                MESOS_OFFER.getSlaveId(),
                ImmutableMap.of(PORT_NAME, PORT)))
        .andReturn(TASK.getAssignedTask());
    expect(
            stateManager.changeState(
                storeProvider, Tasks.id(TASK), Optional.of(PENDING), LOST, LAUNCH_FAILED_MSG))
        .andReturn(StateChangeResult.SUCCESS);
    expect(taskFactory.createFrom(TASK.getAssignedTask(), MESOS_OFFER.getSlaveId()))
        .andReturn(TASK_INFO);

    control.replay();

    assertFalse(
        assigner.maybeAssign(
            storeProvider,
            new ResourceRequest(TASK.getAssignedTask().getTask(), EMPTY),
            TaskGroupKey.from(TASK.getAssignedTask().getTask()),
            Tasks.id(TASK),
            NO_RESERVATION));
  }
 public void visit(TourActivity activity) {
   for (Vehicle vehicle : vehicles) {
     double latestArrTimeAtPrevAct =
         latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
     Location prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
     double potentialLatestArrivalTimeAtCurrAct =
         latestArrTimeAtPrevAct
             - transportCosts.getBackwardTransportTime(
                 activity.getLocation(),
                 prevLocation,
                 latestArrTimeAtPrevAct,
                 route.getDriver(),
                 vehicle)
             - activity.getOperationTime();
     double latestArrivalTime =
         Math.min(
             activity.getTheoreticalLatestOperationStartTime(),
             potentialLatestArrivalTimeAtCurrAct);
     if (latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()) {
       stateManager.putTypedInternalRouteState(
           route, vehicle, InternalStates.SWITCH_NOT_FEASIBLE, true);
     }
     stateManager.putInternalTypedActivityState(
         activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
     latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime;
     location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocation();
   }
 }
Exemple #4
0
  @Override
  public void mouseReleased(MouseEvent e) {
    super.mouseReleased(e);

    StateManager stateManager = graphModel.getStateManager();
    stateManager.changeStateTo(stateManager.getSelectionState());
  }
Exemple #5
0
 @Test
 public void loadAtBeginningShouldBe0() {
   stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
   Capacity routeState =
       stateManager.getRouteState(serviceRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
   assertEquals(0, routeState.get(0));
 }
  /**
   * Gets an instance of a CircleAnnotation that has valid Object Reference.
   *
   * @param library document library
   * @param rect bounding rectangle in user space
   * @return new CircleAnnotation Instance.
   */
  public static CircleAnnotation getInstance(Library library, Rectangle rect) {
    // state manager
    StateManager stateManager = library.getStateManager();

    // create a new entries to hold the annotation properties
    HashMap<Name, Object> entries = new HashMap<Name, Object>();
    // set default link annotation values.
    entries.put(Dictionary.TYPE_KEY, Annotation.TYPE_VALUE);
    entries.put(Dictionary.SUBTYPE_KEY, Annotation.SUBTYPE_CIRCLE);
    // coordinates
    if (rect != null) {
      entries.put(Annotation.RECTANGLE_KEY, PRectangle.getPRectangleVector(rect));
    } else {
      entries.put(Annotation.RECTANGLE_KEY, new Rectangle(10, 10, 50, 100));
    }

    // create the new instance
    CircleAnnotation circleAnnotation = new CircleAnnotation(library, entries);
    circleAnnotation.init();
    circleAnnotation.setPObjectReference(stateManager.getNewReferencNumber());
    circleAnnotation.setNew(true);

    // set default flags.
    circleAnnotation.setFlag(Annotation.FLAG_READ_ONLY, false);
    circleAnnotation.setFlag(Annotation.FLAG_NO_ROTATE, false);
    circleAnnotation.setFlag(Annotation.FLAG_NO_ZOOM, false);
    circleAnnotation.setFlag(Annotation.FLAG_PRINT, true);

    return circleAnnotation;
  }
    // Handler of incoming messages from clients.
    @Override
    public void handleMessage(Message msg) {
      FLog.i(TAG, "Get message: " + msg.what);
      switch (msg.what) {
        case Constants.MSG_REGISTER_CLIENT_REQ:
          {
            if (msg.replyTo != null) {
              mFrontMessenger = msg.replyTo;
              MessengerUtil.setMessenger(mFrontMessenger);
              StateManager.getInstance().registerListener(stateChange);
              FLog.i(TAG, "Client register.");
            } else {
              FLog.i(TAG, "Client register. But front messenger is null.");
            }

            break;
          }
        case Constants.MSG_SET_QCODE_REQ:
          {
            if ((msg != null) && (msg.getData() != null)) {
              String sQCode = msg.getData().getString("QCode");
              FLog.i(TAG, "Set QCode, QCode=" + sQCode);
              mQRcode = sQCode;
              connectType = msg.arg1;
              connectServer();
            }

            break;
          }
        case Constants.MSG_WEBSOCKET_STATE:
          {
            if (null != msg.replyTo) {
              stateChange.onChange(StateManager.getInstance().getCurrentState());
            }
            break;
          }

        case Constants.MSG_DISCONNECT_PC:
          {
            if (connectType == msg.arg1) {
              FLog.i(TAG, "Disconnect PC.");
              closeSwClient();
              mQRcode = "";
              connectType = -1;
              StateManager.getInstance().pushState(new State(State.STATE_PC_DISCONNECT));
            }
            break;
          }

        case Constants.MSG_UNREGISTER_CLIENT:
          {
            FLog.i(TAG, "Unregister client!");
            mFrontMessenger = null;
            MessengerUtil.setMessenger(null);
            StateManager.getInstance().unRegisterListener(stateChange);
            break;
          }
      }
    }
        public void handleMessage(Message msg) {
          FLog.i(TAG, "Connect Handler get message:" + msg.what);

          switch (msg.what) {
            case Constants.HANDLER_MESSAGE:
              {
                if (msg.obj != null) {}

                break;
              }

            case Constants.HANDLER_WS_DISCONNECTED:
              {
                StateManager.getInstance().pushState(new State(State.STATE_DISCONNECTED));
                if (mQRcode != null && !"".equals(mQRcode)) {
                  FLog.i(TAG, "Web socket disconnected. Reconnect...");
                  mConnectHandler.postDelayed(runnable, Constants.WS_RECONNECT_INTERVAL);
                }

                break;
              }

            case Constants.HANDLER_WS_CONNECTED:
              {
                StateManager.getInstance().pushState(new State(State.STATE_CONNECTED));
                mWSManager.sendHiToServer();
                FLog.i(TAG, "Send pair request to PC!");
                break;
              }

            case Constants.HANDLER_PAIR_SUCCESS:
              {
                if (mWSManager != null) {
                  mWSManager.setPCConnectState(true);
                }

                break;
              }

            case Constants.HANDLER_PC_DISCONNECT:
              {
                StateManager.getInstance().pushState(new State(State.STATE_PC_DISCONNECT));
                if (mWSManager != null) {
                  mWSManager.setPCConnectState(false);
                }
                break;
              }

            case Constants.HANDLER_RECEIVED_MSG:
              {
                break;
              }

            default:
              break;
          }

          super.handleMessage(msg);
        }
Exemple #9
0
 @Test
 public void futureMaxLoatAtAct1ShouldBe15() {
   stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
   Capacity atAct1 =
       stateManager.getActivityState(
           serviceRoute.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class);
   assertEquals(15, atAct1.get(0));
 }
Exemple #10
0
 @Test
 public void pastMaxLoatAtAct2ShouldBe10() {
   stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
   Capacity atAct2 =
       stateManager.getActivityState(
           serviceRoute.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class);
   assertEquals(15, atAct2.get(0));
 }
Exemple #11
0
 @Test
 public void when_shipmentroute_loadAtAct3ShouldBe10() {
   stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
   Capacity atAct =
       stateManager.getActivityState(
           shipment_route.getActivities().get(2), InternalStates.LOAD, Capacity.class);
   assertEquals(10, atAct.get(0));
 }
Exemple #12
0
 @Test
 public void when_shipmentroute_pastMaxLoatAtAct4ShouldBe15() {
   stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
   Capacity atAct =
       stateManager.getActivityState(
           shipment_route.getActivities().get(3), InternalStates.PAST_MAXLOAD, Capacity.class);
   assertEquals(15, atAct.get(0));
 }
Exemple #13
0
 private Double getLastTransport(TourActivity activity, VehicleRoute route, StateId id) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return 0.;
   if (activity instanceof End) return stateManager.getRouteState(route, id, Double.class);
   verifyThatRouteContainsAct(activity, route);
   return stateManager.getActivityState(activity, id, Double.class);
 }
 public UpdateVehicleDependentPracticalTimeWindows(
     StateManager stateManager, VehicleRoutingTransportCosts tpCosts) {
   super();
   this.stateManager = stateManager;
   this.transportCosts = tpCosts;
   latest_arrTimes_at_prevAct = new double[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
   location_of_prevAct = new Location[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
 }
Exemple #15
0
 @Test
 public void when_pdroute_loadAtAct2ShouldBe10() {
   stateManager.informInsertionStarts(
       Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
   Capacity atAct2 =
       stateManager.getActivityState(
           pickup_delivery_route.getActivities().get(1), InternalStates.LOAD, Capacity.class);
   assertEquals(10, atAct2.get(0));
 }
Exemple #16
0
    @Override
    public void visit(TourActivity activity) {
      stateManager.putActivityState(activity, last_transport_distance_id, distance(activity));
      stateManager.putActivityState(activity, last_transport_time_id, transportTime(activity));
      stateManager.putActivityState(activity, last_transport_cost_id, transportCost(activity));

      prevAct = activity;
      prevActDeparture = activity.getEndTime();
    }
Exemple #17
0
 @Test
 public void when_pdroute_loadAtBeginningShouldBe5() {
   stateManager.informInsertionStarts(
       Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
   Capacity routeState =
       stateManager.getRouteState(
           pickup_delivery_route, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
   assertEquals(5, routeState.get(0));
 }
 @Before
 public void beforeTests() {
   session = new SessionTester();
   chatManager = new PairChatManager(session);
   session.setLoggedIn(MYSELF);
   final StateManager stateManager = new StateManager(chatManager);
   chat = chatManager.open(OTHER);
   chatStateManager = stateManager.getChatState(chat);
   stateListener = new MockedListener<ChatState>();
   chatStateManager.onChatStateChanged(stateListener);
 }
Exemple #19
0
 @Test
 public void when_pdroute_pastMaxLoatAtAct1ShouldBe15() {
   stateManager.informInsertionStarts(
       Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
   Capacity atAct1 =
       stateManager.getActivityState(
           pickup_delivery_route.getActivities().get(0),
           InternalStates.PAST_MAXLOAD,
           Capacity.class);
   assertEquals(15, atAct1.get(0));
 }
Exemple #20
0
 @Override
 public void finish() {
   // shipment
   // pickups without deliveries
   for (TourActivity act : openShipments.values()) {
     stateManager.putActivityState(act, shipment_id, true);
     shipmentConstraintOnRouteViolated = true;
   }
   stateManager.putRouteState(route, shipment_id, shipmentConstraintOnRouteViolated);
   // backhaul
   stateManager.putRouteState(route, backhaul_id, backhaulConstraintOnRouteViolated);
 }
Exemple #21
0
 @Override
 public void finish() {
   sum_transport_time += route.getEnd().getArrTime() - prevActDeparture;
   sum_too_late +=
       Math.max(
           0,
           route.getEnd().getArrTime()
               - route.getEnd().getTheoreticalLatestOperationStartTime());
   stateManager.putRouteState(route, transport_time_id, sum_transport_time);
   stateManager.putRouteState(route, waiting_time_id, sum_waiting_time);
   stateManager.putRouteState(route, service_time_id, sum_service_time);
   stateManager.putRouteState(route, too_late_id, sum_too_late);
 }
 @Override
 public void onConfigurationChanged(Configuration config) {
   super.onConfigurationChanged(config);
   mStateManager.onConfigurationChange(config);
   // workaround for CR 110382(share menu location wrong after rotating screen)
   // invalidateOptionsMenu();
 }
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
      StateManager.getInstance().switchState(StateType.MENU);
    }

    return true;
  }
  @Test
  public void testAssignNoVetoes() {
    expect(
            filter.filter(
                new UnusedResource(ResourceSlot.from(MESOS_OFFER), OFFER.getAttributes()),
                new ResourceRequest(TASK.getAssignedTask().getTask(), EMPTY)))
        .andReturn(ImmutableSet.of());
    expect(
            stateManager.assignTask(
                storeProvider,
                Tasks.id(TASK),
                MESOS_OFFER.getHostname(),
                MESOS_OFFER.getSlaveId(),
                ImmutableMap.of(PORT_NAME, PORT)))
        .andReturn(TASK.getAssignedTask());
    expect(taskFactory.createFrom(TASK.getAssignedTask(), MESOS_OFFER.getSlaveId()))
        .andReturn(TASK_INFO);

    control.replay();

    assertEquals(
        Assignment.success(TASK_INFO),
        assigner.maybeAssign(
            storeProvider,
            OFFER,
            new ResourceRequest(TASK.getAssignedTask().getTask(), EMPTY),
            Tasks.id(TASK)));
  }
Exemple #25
0
    @Override
    public void visit(TourActivity activity) {
      // waiting time & toolate
      double waitAtAct = 0.;
      double tooLate = 0.;
      if (activityPolicy.equals(ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)) {
        waitAtAct =
            Math.max(
                0, activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime());
        tooLate =
            Math.max(0, activity.getArrTime() - activity.getTheoreticalLatestOperationStartTime());
      }
      sum_waiting_time += waitAtAct;
      sum_too_late += tooLate;
      // transport time
      double transportTime = activity.getArrTime() - prevActDeparture;
      sum_transport_time += transportTime;
      prevActDeparture = activity.getEndTime();
      // service time
      sum_service_time +=
          activityCosts.getActivityDuration(
              activity, activity.getArrTime(), route.getDriver(), route.getVehicle());

      stateManager.putActivityState(activity, transport_time_id, sum_transport_time);
    }
Exemple #26
0
 @Override
 public void finish() {
   double distance =
       distanceCalculator.getDistance(prevAct.getLocation(), route.getEnd().getLocation());
   sum_distance += distance;
   stateManager.putRouteState(route, distance_id, sum_distance);
 }
  @Test
  public void testDelayedStart() throws Exception {
    expectJobAccepted();
    expectJobFetch();

    // Query to test if live tasks exist for the job.
    expectActiveTaskFetch(TASK);

    // Live tasks exist, so the cron manager must delay the cron launch.
    delayExecutor.execute(capture(delayLaunchCapture));

    // The cron manager will then try to initiate the kill.
    scheduler.killTasks((Query.Builder) anyObject(), eq(CronJobManager.CRON_USER));

    // Immediate query and delayed query.
    expectActiveTaskFetch(TASK).times(2);

    // Simulate the live task disappearing.
    expectActiveTaskFetch();

    stateManager.insertPendingTasks(sanitizedConfiguration.getTaskConfigs());

    control.replay();

    cron.receiveJob(sanitizedConfiguration);
    cron.startJobNow(job.getKey());
    assertEquals(ImmutableSet.of(job.getKey()), cron.getPendingRuns());
    delayLaunchCapture.getValue().run();
    assertEquals(ImmutableSet.<IJobKey>of(), cron.getPendingRuns());
  }
  @Test
  public void testAssignNoVetoes() throws Exception {
    expect(offerManager.getOffers(GROUP_KEY)).andReturn(ImmutableSet.of(OFFER));
    offerManager.launchTask(MESOS_OFFER.getId(), TASK_INFO);
    expect(tierManager.getTier(TASK.getAssignedTask().getTask())).andReturn(DEFAULT);
    expect(filter.filter(UNUSED, RESOURCE_REQUEST)).andReturn(ImmutableSet.of());
    expect(
            stateManager.assignTask(
                storeProvider,
                Tasks.id(TASK),
                MESOS_OFFER.getHostname(),
                MESOS_OFFER.getSlaveId(),
                ImmutableMap.of(PORT_NAME, PORT)))
        .andReturn(TASK.getAssignedTask());
    expect(taskFactory.createFrom(TASK.getAssignedTask(), MESOS_OFFER.getSlaveId()))
        .andReturn(TASK_INFO);

    control.replay();

    assertTrue(
        assigner.maybeAssign(
            storeProvider,
            new ResourceRequest(TASK.getAssignedTask().getTask(), EMPTY),
            TaskGroupKey.from(TASK.getAssignedTask().getTask()),
            Tasks.id(TASK),
            ImmutableMap.of(SLAVE_ID, GROUP_KEY)));
  }
Exemple #29
0
 /**
  * @param activity to get the load from (after activity)
  * @return load right after the specified activity. If act is Start, it returns the load
  *     atBeginning of the specified route. If act is End, it returns the load atEnd of specified
  *     route. Returns null if no load can be found.
  */
 public Capacity getLoadRightAfterActivity(TourActivity activity, VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return getLoadAtBeginning(route);
   if (activity instanceof End) return getLoadAtEnd(route);
   verifyThatRouteContainsAct(activity, route);
   return stateManager.getActivityState(activity, InternalStates.LOAD, Capacity.class);
 }
Exemple #30
0
 /**
  * @param activity to check skill constraint
  * @param route that must contain specified activity
  * @return true if vehicle does not have the skills to conduct specified activity, false
  *     otherwise. Returns null if specified route or activity is null or if route does not contain
  *     specified activity or if skill state connot be found. If specified activity is Start or
  *     End, it returns false.
  */
 public Boolean hasSkillConstraintViolationAtActivity(TourActivity activity, VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return false;
   if (activity instanceof End) return false;
   verifyThatRouteContainsAct(activity, route);
   return stateManager.getActivityState(activity, skill_id, Boolean.class);
 }