Esempio n. 1
0
  protected void populate(Network myNetwork) {

    Scenario myScenario = myNetwork.getMyScenario();

    // Note: It is assumed that this comes *before* SplitRatioProfile.populate

    this.myNetwork = myNetwork;

    nOut = 0;
    if (getOutputs() != null) {
      nOut = getOutputs().getOutput().size();
      output_link = new Link[nOut];
      for (int i = 0; i < nOut; i++) {
        edu.berkeley.path.beats.jaxb.Output output = getOutputs().getOutput().get(i);
        output_link[i] = myNetwork.getLinkWithId(output.getLinkId());
      }
    }

    nIn = 0;
    if (getInputs() != null) {
      nIn = getInputs().getInput().size();
      input_link = new Link[nIn];
      for (int i = 0; i < nIn; i++) {
        edu.berkeley.path.beats.jaxb.Input input = getInputs().getInput().get(i);
        input_link[i] = myNetwork.getLinkWithId(input.getLinkId());
      }
    }

    isTerminal = nOut == 0 || nIn == 0;
    istrivialsplit = nOut <= 1;
    has_profile = false;

    if (isTerminal) return;

    if (!istrivialsplit
        && myScenario.split_logger_prefix != null
        && !myScenario.split_logger_prefix.isEmpty())
      split_ratio_logger = new SplitRatioLogger(this);

    // initialize the split ratio matrix
    // NOTE: SHOULD THIS GO IN RESET?
    splitratio_nominal = BeatsMath.zeros(nIn, nOut, myScenario.get.numVehicleTypes());
    BeatsMath.normalize(splitratio_nominal);

    // default node flow and split solvers
    //        node_behavior = new NodeBehavior(this,
    //                                          new Node_SplitRatioSolver_Greedy(this) ,
    //                                          new Node_FlowSolver_LNCTM(this) ,
    //                                          new Node_SupplyPartitioner(this) );
  }
Esempio n. 2
0
  protected Controller(
      Scenario myScenario,
      edu.berkeley.path.beats.jaxb.Controller jaxbC,
      Controller.Algorithm myType) {

    this.myScenario = myScenario;
    this.myType = myType;
    this.jaxbController = jaxbC;
    this.ison = false;
    //			this.activationTimes=new ArrayList<ActivationTimes>();
    this.dtinseconds = jaxbC.getDt() > 0 ? jaxbC.getDt() : myScenario.get.simdtinseconds();

    // Copy tables
    tables = new java.util.HashMap<String, Table>();
    for (edu.berkeley.path.beats.jaxb.Table table : jaxbC.getTable()) {
      if (tables.containsKey(table.getName()))
        BeatsErrorLog.addError("Table '" + table.getName() + "' already exists");
      tables.put(table.getName(), new Table(table));
    }

    //			// Get activation times and sort
    //			if (jaxbC.getActivationIntervals()!=null)
    //				for (edu.berkeley.path.beats.jaxb.Interval tinterval :
    // jaxbC.getActivationIntervals().getInterval())
    //					if(tinterval!=null)
    //						activationTimes.add(new
    // ActivationTimes(tinterval.getStartTime(),tinterval.getEndTime()));
    //			Collections.sort(activationTimes);

    // below this does not apply for scenario-less controllers  ..............................
    if (myScenario == null) return;

    samplesteps = BeatsMath.round(dtinseconds / myScenario.get.simdtinseconds());

    // read target actuators
    actuators = new ArrayList<Actuator>();
    actuator_usage = new ArrayList<String>();
    if (jaxbC.getTargetActuators() != null
        && jaxbC.getTargetActuators().getTargetActuator() != null) {
      for (TargetActuator ta : jaxbC.getTargetActuators().getTargetActuator()) {
        Actuator act = myScenario.get.actuatorWithId(ta.getId());
        actuators.add(act);
        act.setMyController(this);
        actuator_usage.add(ta.getUsage() == null ? "" : ta.getUsage());
      }
    }

    // read feedback sensors
    sensors = new ArrayList<Sensor>();
    sensor_usage = new ArrayList<String>();
    if (jaxbC.getFeedbackSensors() != null
        && jaxbC.getFeedbackSensors().getFeedbackSensor() != null) {
      for (FeedbackSensor fs : jaxbC.getFeedbackSensors().getFeedbackSensor()) {
        sensors.add(getMyScenario().get.sensorWithId(fs.getId()));
        sensor_usage.add(fs.getUsage() == null ? "" : fs.getUsage());
      }
    }
  }
Esempio n. 3
0
  protected void validate() {

    // check that type was read correctly
    if (myType == null)
      BeatsErrorLog.addError("Controller with ID=" + getId() + " has the wrong type.");

    // validations below this make sense only in the context of a scenario
    if (myScenario == null) return;

    // check that sample dt is an integer multiple of network dt
    if (!BeatsMath.isintegermultipleof(dtinseconds, myScenario.get.simdtinseconds()))
      BeatsErrorLog.addError(
          "Time step for controller ID="
              + getId()
              + " is not a multiple of the simulation time step.");

    //		// check that activation times are valid.
    //		for (int i=0; i<activationTimes.size(); i++ ){
    //			activationTimes.get(i).validate();
    //			if (i<activationTimes.size()-1)
    //				activationTimes.get(i).validateWith(activationTimes.get(i+1));
    //		}

  }
Esempio n. 4
0
 public Double getSplitRatio(int in, int out) {
   return BeatsMath.sum(splitratio_nominal[in][out]);
 }
Esempio n. 5
0
 public void sample_split_ratio_profile() {
   if (has_profile) splitratio_nominal = BeatsMath.copy(my_profile.getCurrentSplitRatio());
 }
Esempio n. 6
0
  public void update_flows() {

    if (isTerminal) return;

    int e, i, j;
    Scenario myScenario = myNetwork.getMyScenario();
    int numEnsemble = myScenario.get.numEnsemble();
    int numVTypes = myScenario.get.numVehicleTypes();

    // Select a nominal split ratio from profile, event, or controller
    if (istrivialsplit) {
      // nominal is all ones
      splitratio_nominal = BeatsMath.ones(nIn, nOut, numVTypes);
    } else {
      sample_split_ratio_profile();
      sample_split_controller();
    }

    for (e = 0; e < numEnsemble; e++) {

      Double[][][] splitratio_perturbed;

      if (my_profile == null || istrivialsplit) {
        splitratio_perturbed = splitratio_nominal; // BeatsMath.nans(nIn,nOut,numVTypes);
      } else {
        if (!my_profile.isdeterministic()
            && my_profile
                .hasConcentrationParameters()) // &&
                                               // my_profile.isCurrentConcentrationParametersValid())
        splitratio_perturbed =
              SplitRatioPerturber.sampleFromConcentrationParametersOnce(
                  my_profile.getCurrentConcentration());
        else if (!my_profile.isdeterministic() && nOut == 2 && nIn == 1)
          splitratio_perturbed =
              SplitRatioPerturber.perturb2OutputSplitOnce(splitratio_nominal, my_profile);
        else splitratio_perturbed = splitratio_nominal;
      }

      // compute applied split ratio matrix
      Double[][][] splitratio_applied =
          istrivialsplit
              ? splitratio_perturbed
              : node_behavior.sr_solver.computeAppliedSplitRatio(splitratio_perturbed, e);

      /////////////////////////////////////////////////
      // write first to logger
      if (split_ratio_logger != null && e == 0) split_ratio_logger.write(splitratio_applied);
      /////////////////////////////////////////////////

      // compute node flows ..........................................
      Node_FlowSolver.IOFlow IOflow =
          node_behavior.flow_solver.computeLinkFlows(splitratio_applied, e);

      if (IOflow == null) return;

      // assign flow to input links ..................................
      for (i = 0; i < nIn; i++) input_link[i].setOutflow(e, IOflow.getIn(i));

      // assign flow to output links .................................
      for (j = 0; j < nOut; j++) output_link[j].setInflow(e, IOflow.getOut(j));
    }
  }
    public void update(Clock clock) {

      int i, j;
      int e = 0;

      if (measured_flow_profile_veh.sample(false, clock))
        current_flow_veh = measured_flow_profile_veh.getCurrentSample() * knob;

      if (BeatsMath.equals(current_flow_veh, 0d)) {
        beta = 0d;
        return;
      }

      // Sf: total demand from "feeds"
      Double Sf = 0d;
      for (Link link : feeds) Sf += BeatsMath.sum(link.get_out_demand_in_veh(e));

      // compute demand to non-measured, total $+phi, and from feed links phi
      ArrayList<Double> beta_array = new ArrayList<Double>();

      // compute sr normalization factor for feeding links
      //            for(i=0;i<myNode.getInput_link().length;i++) {
      //                if (!feeds.contains( myNode.input_link[i]))
      //                    continue;
      //                alpha_tilde[i] = 0d;
      //                for (j = 0; j < myNode.nOut; j++)
      //                    if(not_meas.contains( myNode.output_link[j]))
      //                        alpha_tilde[i] += myNode.getSplitRatio(i, j);
      //            }

      // freeflow case
      beta_array.add(0d);
      beta_array.add(current_flow_veh / Sf);

      // rest
      for (j = 0; j < myNode.nOut; j++) {
        Link outlink = myNode.output_link[j];

        // case for the measured
        if (not_meas.contains(outlink)) {

          double dem_non_feed = 0d; // demand on j from non-feeding links
          double dem_feed = 0d; // demand on j from feeding links

          for (i = 0; i < myNode.nIn; i++) {
            Link inlink = myNode.input_link[i];
            //                        Double alpha_ij = myNode.getSplitRatio(i,j);
            Double Si = BeatsMath.sum(inlink.get_out_demand_in_veh(e));
            if (feeds.contains(inlink)) dem_feed += Si; // alpha_ij * Si / alpha_tilde[i];
            else // otherwise add to total
            dem_non_feed += 0d; // alpha_ij * Si;
          }

          Double R = outlink.get_available_space_supply_in_veh(e);

          double num = current_flow_veh * (dem_non_feed + dem_feed);
          double den = Sf * R + dem_feed * current_flow_veh;

          beta_array.add(den > 0 ? num / den : Double.POSITIVE_INFINITY);
        }
      }

      beta = Math.min(BeatsMath.max(beta_array), 1d);
    }