コード例 #1
0
ファイル: ALNSSCSolver.java プロジェクト: vpillac/vroom
  /** Find an initial solution */
  public void initialization() {
    // ----------------------------------------
    // Setup the initialization
    setInit(
        (TRSPConstructiveHeuristic)
            getParams()
                .newInstance(
                    RUN_INIT_HEUR,
                    getInstance(),
                    getParams(),
                    getTourCtrHandler(),
                    getParams().newInitCostDelegate()));
    // ----------------------------------------
    mInitTimer.reset();
    mInitTimer.start();
    if (getParams().get(TRSPGlobalParameters.ALNS_PARALLEL)) {
      // TODO parallelize this
      int size =
          Math.min(
              getParams().get(TRSPGlobalParameters.ALNS_PALNS_POOL_SIZE),
              getParams().get(TRSPGlobalParameters.THREAD_COUNT));
      mInitPool = new ArrayList<TRSPSolution>(size);
      while (mInitPool.size() < size) {
        getInit().call();
        mInitPool.add(getInit().getSolution());
      }
      Collections.sort(mInitPool, new SolutionComparator<>(OptimizationSense.MINIMIZATION));
      mInitSol = mInitPool.get(mInitPool.size() - 1).clone();
    } else {
      getInit().call();
      setInitSol(getInit().getSolution());
    }
    mInitTimer.stop();

    getInitSol().getCostDelegate().unsetUnservedPenalty();
    getInitSol().getCostDelegate().evaluateSolution(getInitSol(), true, true);
  }
コード例 #2
0
ファイル: ALNSSCSolver.java プロジェクト: vpillac/vroom
  @Override
  public Object[] getStats(BestKnownSolutions bks, int runId, int runNum) {
    String group =
        getInstance().getName().substring(0, (getInstance().getName().contains("RC") ? 3 : 2));

    String instanceName = getInstance().getName().replace(".txt", "");

    TRSPCostDelegate wtDel;
    // sCVRPTW
    if (getParams().isCVRPTW()) wtDel = new TRSPDistance();
    else wtDel = new TRSPWorkingTime();
    TRSPTourBalance tbDel =
        new TRSPTourBalance(
            wtDel, getParams().get(TRSPGlobalParameters.BALANCE_COST_DELEGATE_MEASURE));

    double init_wt = wtDel.evaluateSolution(getInitSol(), true, true);
    // double init_wt_dev = tbDel.evaluateSolution(getInitSol(), true, true);
    double alns_wt = wtDel.evaluateSolution(getALNSSol(), true, true);
    // double alns_wt_dev = tbDel.evaluateSolution(getALNSSol(), true, true);
    double postop_wt = wtDel.evaluateSolution(getFinalSolution(), true, true);
    // double postop_wt_dev = tbDel.evaluateSolution(getFinalSolution(), true, true);
    double postop_bbgap = Double.NaN;
    if (getPostOp() != null) {
      try {
        double mipObj = getPostOp().getModel().get(DoubleAttr.ObjVal);
        double mipLB = getPostOp().getModel().get(DoubleAttr.ObjBound);
        postop_bbgap = mipLB != 0 ? (mipObj - mipLB) / mipObj : mipObj / 100;
      } catch (GRBException e) {
        TRSPLogging.getProcedureLogger()
            .exception(this.getClass().getSimpleName() + ".collectStats", e);
      }
    }
    Object[] stats =
        new Object[] {
          runId,
          getInstance().getName(), // name
          group, // group
          getInstance().getRequestCount(), // size
          getInstance().getFleet().size(), // crew count
          runNum,
          getComment(), // comment
          mInitTimer.readTimeS(), // init_time
          getInit().getIterationCount(), // init_it
          // mInit.getAssignmentStrategy(),// init_strat
          getInit().getStatus(), // init_status
          getInitSol().getUnservedCount(), // init_unserved
          init_wt, // init_wt
          // init_wt_dev,// init_wt_dev
          getALNS().getTimer().readTimeS(), // alns_time
          getALNS().getStoppingCriterion().getIterationCount(), // alns_it
          getALNSSol().getUnservedCount(), // alns_unserved
          alns_wt, // alns_wt
          // alns_wt_dev,// alns_wt_dev
          getALNSSol().getActualTourCount(), // alns_K
          (init_wt - alns_wt) / init_wt, // wt imp
          // (init_wt_dev - alns_wt_dev) / init_wt_dev, // wt dev imp
          getChecker().checkSolution(getALNSSol()), // alns_feasible
          getPostOp() == null ? 0l : getPostOp().getTimer().readTimeS(), // postop_time
          getFinalSolution().getUnservedCount(), // postop_unserved
          postop_wt, // postop_wt
          // postop_wt_dev, // postop_wt_dev
          getFinalSolution().getActualTourCount(), // postop_K
          (alns_wt - postop_wt) / alns_wt, // postop_wt improvement
          // (alns_wt_dev - postop_wt_dev) / alns_wt_dev, // postop_wt_dev improvement
          getChecker().checkSolution(getFinalSolution()), // postop_checksol
          postop_bbgap, // postop_gap
          getPostOp() != null
              ? getPostOp().getStatus()
              : SolverStatus.UNKNOWN_STATUS, // postop_status
          getPostOp() != null ? getPostOp().getColumnCount() : 0, // postop_pool_size
          getHashPoolCollisionCount(), // postop_pool_collisions
          bks.getBKS(instanceName), // BKS
          bks.getGapToBKS(instanceName, alns_wt, OptimizationSense.MINIMIZATION), // ALNS GAP
          bks.getGapToBKS(instanceName, postop_wt, OptimizationSense.MINIMIZATION), // POSTOP GAP
          bks.getIntValue(instanceName, "K"), // BKS - K
          bks.isOptimal(instanceName) ? 1 : 0, // BKS is optimal?
          Utilities.toShortString(getParams().get(TRSPGlobalParameters.RUN_SEEDS)), // seeds
          getFinalSolution().toShortString()
        };
    return stats;
  }
コード例 #3
0
ファイル: ALNSSCSolver.java プロジェクト: vpillac/vroom
  @Override
  public TRSPSolution call() {
    TRSPLogging.getProcedureLogger()
        .info(
            this.getClass().getSimpleName() + "[start ]: Solving instance %s (I=%s, SC=%s)",
            getInstance().getName(),
            getParams().get(TRSPGlobalParameters.ALNS_MAX_IT),
            getParams().get(TRSPGlobalParameters.SC_ENABLED));

    if (getInitSol() == null) {
      initialization();
      TRSPLogging.getProcedureLogger()
          .info(
              this.getClass().getSimpleName() + "[init  ]: Initialization finished in %.1fs",
              mInitTimer.readTimeS());
      TRSPLogging.getProcedureLogger()
          .info(
              this.getClass().getSimpleName() + "[init  ]: Initial solution: %.3f (%s)",
              getInitSol().getObjectiveValue(),
              getInitSol().getUnservedCount());
      String err = getChecker().checkSolution(getInitSol());
      if (!err.isEmpty()) {
        TRSPLogging.getProcedureLogger()
            .warn(this.getClass().getSimpleName() + "[init  ]:  Infeasibility: %s", err);
      }
    }

    setupALNS();
    if (ParallelALNS.class.isAssignableFrom(getALNS().getClass()))
      TRSPLogging.getProcedureLogger()
          .info(
              this.getClass().getSimpleName() + "[init  ]: Penalty: %.3f - Initial pool: %s",
              getInitSol().getCostDelegate().getUnservedPenalty(),
              ((ParallelALNS<?>) getALNS()).getSolPool());
    alns();
    TRSPLogging.getProcedureLogger()
        .info(
            this.getClass().getSimpleName() + "[alns  ]: ALNS finished in %.1fs %s",
            getALNS().getTimer().readTimeS(),
            getALNS().getStoppingCriterion());
    if (ParallelALNS.class.isAssignableFrom(getALNS().getClass()))
      TRSPLogging.getProcedureLogger()
          .info(
              this.getClass().getSimpleName() + "[alns  ]: Final pool: %s",
              ((ParallelALNS<?>) getALNS()).getSolPool());
    if (getALNSSol() != null)
      TRSPLogging.getProcedureLogger()
          .info(
              this.getClass().getSimpleName() + "[alns  ]: ALNS solution  : %.3f (%s)",
              getALNSSol().getObjectiveValue(),
              getALNSSol().getUnservedCount());
    String err = getChecker().checkSolution(getALNSSol());
    if (!err.isEmpty()) {
      TRSPLogging.getProcedureLogger()
          .warn(this.getClass().getSimpleName() + "[alns  ]:  Infeasibility: %s", err);
    }

    if (getParams().get(TRSPGlobalParameters.SC_ENABLED) && getALNSSol() != null) {
      TRSPLogging.getProcedureLogger()
          .info(this.getClass().getSimpleName() + "[postop]: Post-optimization");
      setupPostOp();
      postOp();
      TRSPLogging.getProcedureLogger()
          .info(
              this.getClass().getSimpleName() + "[postop]: Post-optimization finished in %.1fs",
              getPostOp().getTimer().readTimeS());
      err = getChecker().checkSolution(getFinalSolution());
      if (!err.isEmpty()) {
        TRSPLogging.getProcedureLogger()
            .warn(this.getClass().getSimpleName() + "[end  ]:  Infeasibility: %s", err);
      }
    } else {
      setFinalSolution(getALNSSol());
    }

    TRSPLogging.getProcedureLogger()
        .info(
            this.getClass().getSimpleName() + "[end   ]: Final solution : %.3f (%s)",
            getFinalSolution() != null ? getFinalSolution().getObjectiveValue() : Double.NaN,
            getFinalSolution() != null ? getFinalSolution().getUnservedCount() : "na");

    return getFinalSolution();
  }