/** * Fills link_data_total table * * @param link * @param param output parameters * @return the stored row * @throws Exception */ private LinkDataTotal fill_total(Link link, OutputParameters params) throws Exception { LinkDataTotal db_ldt = new LinkDataTotal(); db_ldt.setLinkId(str2id(link.getId())); db_ldt.setNetworkId(str2id(link.myNetwork.getId())); db_ldt.setDataSources(db_simulation_run.getDataSources()); db_ldt.setTs(ts.getTime()); db_ldt.setAggregation("raw"); db_ldt.setType("mean"); db_ldt.setCellNumber(Integer.valueOf(0)); // mean density, vehicles double density = SiriusMath.sum(link.cumulative_density[0]) / params.getNsteps(); db_ldt.setDensity(BigDecimal.valueOf(density)); FundamentalDiagram fd = link.currentFD(0); if (null != fd) { if (params.doExportFlows()) { // input flow, vehicles db_ldt.setInFlow(BigDecimal.valueOf(SiriusMath.sum(link.cumulative_inflow[0]))); // output flow, vehicles double outflow = SiriusMath.sum(link.cumulative_outflow[0]); db_ldt.setOutFlow(BigDecimal.valueOf(outflow)); // free flow speed, m/s BigDecimal ffspeed = fd.getFreeFlowSpeed(); // speed, m/s if (density <= 0) db_ldt.setSpeed(ffspeed); else { double speed = outflow * link.getLength().doubleValue() / (params.getOutputPeriod() * density); if (null != ffspeed && speed > ffspeed.doubleValue()) db_ldt.setSpeed(ffspeed); else if (!Double.isNaN(speed)) db_ldt.setSpeed(BigDecimal.valueOf(speed)); } } // free flow speed, m/s db_ldt.setFreeFlowSpeed(fd.getFreeFlowSpeed()); // critical speed, m/s db_ldt.setCriticalSpeed(fd.getCriticalSpeed()); // congestion wave speed, m/s db_ldt.setCongestionWaveSpeed(fd.getCongestionSpeed()); // maximum flow, vehicles per second per lane db_ldt.setCapacity(fd.getCapacity()); // jam density, vehicles per meter per lane db_ldt.setJamDensity(fd.getJamDensity()); // capacity drop, vehicle per second per lane db_ldt.setCapacityDrop(fd.getCapacityDrop()); } db_ldt.save(); return db_ldt; }
protected void updatePermitOpposingHold() { switch (bulbcolor) { case GREEN: // iff I am about to go off and there is no transition time permitopposinghold = forceoff_requested && actualyellowtime == 0 && redcleartime == 0; break; case YELLOW: // iff near end yellow time and there is no red clear time permitopposinghold = SiriusMath.greaterorequalthan(bulbtimer.getT(), actualyellowtime - bulbtimer.dt) && redcleartime == 0; break; case RED: // iff near end of red clear time and not starting again. permitopposinghold = SiriusMath.greaterorequalthan(bulbtimer.getT(), redcleartime - bulbtimer.dt) && !hold_requested; break; } }
protected void update(boolean hold_approved, boolean forceoff_approved) { double bulbt = bulbtimer.getT(); if (!protectd) { if (permissive) return; else { setPhaseColor(Signal.BulbColor.RED); return; } } // execute this state machine until "done". May be more than once if // some state has zero holding time (eg yellowtime=0) boolean done = false; while (!done) { switch (bulbcolor) { // ............................................................................................. case GREEN: setPhaseColor(Signal.BulbColor.GREEN); // permitopposinghold = false; // Force off if (forceoff_approved) { setPhaseColor(Signal.BulbColor.YELLOW); mySignal.completedPhases.add( mySignal .new PhaseData( myNEMA, mySignal.myScenario.clock.getT() - bulbtimer.getT(), bulbtimer.getT())); bulbtimer.reset(); // FlushAllStationCallsAndConflicts(); done = actualyellowtime > 0; } else done = true; break; // ............................................................................................. case YELLOW: setPhaseColor(Signal.BulbColor.YELLOW); // set permitopposinghold one step ahead of time so that other phases update correctly // next time. // permitopposinghold = false; // if( SiriusMath.greaterorequalthan(bulbt,actualyellowtime-bulbtimer.dt) && // redcleartime==0) // permitopposinghold = true; // yellow time over, go immediately to red if redcleartime==0 if (SiriusMath.greaterorequalthan(bulbt, actualyellowtime)) { setPhaseColor(Signal.BulbColor.RED); bulbtimer.reset(); done = redcleartime > 0; } else done = true; break; // ............................................................................................. case RED: setPhaseColor(Signal.BulbColor.RED); // if( // SiriusMath.greaterorequalthan(bulbt,redcleartime-myNode.getMyNetwork().getTP()*3600f // && !goG ) // if( SiriusMath.greaterorequalthan(bulbt,redcleartime-bulbtimer.dt) && !hold_approved // ) // permitopposinghold = true; // else // permitopposinghold = false; // if hold, set to green, go to green, etc. if (hold_approved) { setPhaseColor(Signal.BulbColor.GREEN); bulbtimer.reset(); // Unregister calls (for reading conflicting calls) // FlushAllStationCallsAndConflicts(); // GCG ????? done = !forceoff_approved; } else done = true; break; } } }