private synchronized void recalcFlowCapacity() { double baseFlowCapacityPerSec = this.getCapacity() / getCapacityPeriod(); variableFlowCapacity.recalc(changeEvents, TimeVariantAttribute.FLOW_CAPACITY_GETTER, baseFlowCapacityPerSec); }
/** * This method returns the capacity as set in the xml defining the network. Be aware * that this capacity is not normalized in time, it depends on the period set * in the network file (the capperiod attribute). * @param time - the current time * @return the capacity per network's capperiod timestep */ @Override public synchronized double getCapacity(final double time) { return getFlowCapacityPerSec(time) * getCapacityPeriod(); }
private synchronized void recalcFreespeed() { variableFreespeed.recalc(changeEvents, TimeVariantAttribute.FREESPEED_GETTER, this.getFreespeed() ); }
assertEquals(10.0, link.getFreespeed(Time.UNDEFINED_TIME), EPSILON); assertEquals(10.0, NetworkUtils.getFreespeedTravelTime(link, Time.UNDEFINED_TIME), EPSILON); change.addLink(link); change.setFreespeedChange(new ChangeValue(ChangeType.ABSOLUTE_IN_SI_UNITS, 20)); link.applyEvent(change); link.applyEvent(change2); change3.addLink(link); change3.setFreespeedChange(new ChangeValue(ChangeType.ABSOLUTE_IN_SI_UNITS, 30)); link.applyEvent(change3); change4.addLink(link); change4.setFreespeedChange(new ChangeValue(ChangeType.OFFSET_IN_SI_UNITS, +22.)); link.applyEvent(change4); assertEquals(10.0, link.getFreespeed(Time.UNDEFINED_TIME), EPSILON); // at undefined time, return base value assertEquals(10.0, link.getFreespeed(7*3600.0 - 1.0), EPSILON); assertEquals(20.0, link.getFreespeed(7*3600.0), EPSILON); assertEquals(20.0, link.getFreespeed(8*3600.0-1), EPSILON); assertEquals(60.0, link.getFreespeed(8*3600.0), EPSILON); assertEquals(60.0, link.getFreespeed(10*3600.0-1), EPSILON); assertEquals(30.0, link.getFreespeed(10*3600.0), EPSILON); assertEquals(30.0, link.getFreespeed(18*3600.0), EPSILON); assertEquals(52.0, link.getFreespeed(19.1*3600.0), EPSILON); change4.addLink(link); change4.setFreespeedChange(new ChangeValue(ChangeType.ABSOLUTE_IN_SI_UNITS, 40));
assertEquals(3600.0, link.getCapacity(org.matsim.core.utils.misc.Time.UNDEFINED_TIME), EPSILON); assertEquals(1.0, link.getFlowCapacityPerSec(org.matsim.core.utils.misc.Time.UNDEFINED_TIME), EPSILON); change.addLink(link); change.setFlowCapacityChange(new ChangeValue(ChangeType.ABSOLUTE_IN_SI_UNITS, 2)); link.applyEvent(change); assertEquals(3600.0, link.getCapacity(org.matsim.core.utils.misc.Time.UNDEFINED_TIME), EPSILON); assertEquals(1.0, link.getFlowCapacityPerSec(org.matsim.core.utils.misc.Time.UNDEFINED_TIME), EPSILON); assertEquals(2.0, link.getFlowCapacityPerSec(7*3600), EPSILON);
assertEquals(1.0, link.getNumberOfLanes(org.matsim.core.utils.misc.Time.UNDEFINED_TIME), EPSILON); change.addLink(link); change.setLanesChange(new ChangeValue(ChangeType.ABSOLUTE_IN_SI_UNITS, 2.0)); link.applyEvent(change); assertEquals(1.0, link.getNumberOfLanes(org.matsim.core.utils.misc.Time.UNDEFINED_TIME), EPSILON); assertEquals(2.0, link.getNumberOfLanes(7*3600), EPSILON);
/** * Adds a single network change event and applies it to the corresponding * links. * * @param event * a network change event. */ @Override public void addNetworkChangeEvent(final NetworkChangeEvent event) { this.networkChangeEvents.add(event); for (Link link : event.getLinks()) { if (link instanceof TimeVariantLinkImpl) { ((TimeVariantLinkImpl)link).applyEvent(event); } else { throw new IllegalArgumentException("Link " + link.getId().toString() + " is not timeVariant. " + "Did you make the network factory time variant? The easiest way to achieve this is " + "either in the config file, or syntax of the type\n" + "config.network().setTimeVariantNetwork(true);\n" + "Scenario scenario = ScenarioUtils.load/createScenario(config);\n" + "Note that the scenario needs to be created _after_ the config option is set, otherwise" + "the factory will already be there."); } } }
private synchronized void recalcLanes() { variableLanes.recalc(changeEvents, TimeVariantAttribute.LANES_GETTER, this.getNumberOfLanes() ); } }
public static TimeVariantLinkImpl createLinkWithFixedIntervalAttributes(final Id<Link> id, final Node from, final Node to, final Network network, final double length, final double freespeed, final double capacity, final double lanes, final int interval, final int maxTime) { return new TimeVariantLinkImpl(id, from, to, network, length, freespeed, capacity, lanes, new FixedIntervalTimeVariantAttribute(interval, maxTime), new FixedIntervalTimeVariantAttribute(interval, maxTime), new FixedIntervalTimeVariantAttribute(interval, maxTime)); }
@Override public Link createLink(Id<Link> id, Node from, Node to, Network network, double length, double freespeed, double capacity, double nOfLanes) { return TimeVariantLinkImpl.createLinkWithFixedIntervalAttributes(id, from, to, network, length, freespeed, capacity, nOfLanes, interval, maxTime); } }
@Override public Link createLink(Id<Link> id, Node from, Node to, Network network, double length, double freespeed, double capacity, double nOfLanes) { return TimeVariantLinkImpl.createLinkWithVariableIntervalAttributes(id, from, to, network, length, freespeed, capacity, nOfLanes); }
/** * Sets the network change events and replaces existing events. Before * events are applied to their corresponding links, all links are reset to * their initial state. Pass an empty event list to reset the complete network. * * @param events a list of events. */ @Override public void setNetworkChangeEvents(final List<NetworkChangeEvent> events) { this.networkChangeEvents.clear(); for(Link link : getLinks().values()) { if (link instanceof TimeVariantLinkImpl) { ((TimeVariantLinkImpl)link).clearEvents(); } // Presumably, there is no exception here if this fails because it can be interpreted: maybe only some links are time-dependent // and others are not, and it is sufficient if the time-dependent ones can be configured by the addNetworkChangeEvent method. // kai, jul'16 } for (NetworkChangeEvent event : events) { this.addNetworkChangeEvent(event); } }
assertEquals(10.0, link.getFreespeed(Time.UNDEFINED_TIME), EPSILON); assertEquals(10.0, NetworkUtils.getFreespeedTravelTime(link, Time.UNDEFINED_TIME), EPSILON); change.addLink(link); change.setFreespeedChange(new ChangeValue(ChangeType.FACTOR, 0.5)); link.applyEvent(change); assertEquals(10.0, link.getFreespeed(Time.UNDEFINED_TIME), EPSILON); // at undefined time, return base value assertEquals(10.0, link.getFreespeed(7*3600.0 - 1.0), EPSILON); // one second before change, still base value assertEquals(10.0, link.getFreespeed(7*3600.0 - 0.1), EPSILON); // just before change, still base value assertEquals(5.0, link.getFreespeed(7*3600.0), EPSILON); // just on time of change, new value assertEquals(5.0, link.getFreespeed(8*3600.0), EPSILON); // some time later, still new value
event.addLink(link1); event.setFreespeedChange(new ChangeValue(NetworkChangeEvent.ChangeType.ABSOLUTE_IN_SI_UNITS,10.)); ((TimeVariantLinkImpl)link1).applyEvent(event); event.addLink(link3); event.setFreespeedChange(new ChangeValue(NetworkChangeEvent.ChangeType.FACTOR,6.)); ((TimeVariantLinkImpl)link3).applyEvent(event);
public static TimeVariantLinkImpl createLinkWithVariableIntervalAttributes(final Id<Link> id, final Node from, final Node to, final Network network, final double length, final double freespeed, final double capacity, final double lanes) { return new TimeVariantLinkImpl(id, from, to, network, length, freespeed, capacity, lanes, new VariableIntervalTimeVariantAttribute(), new VariableIntervalTimeVariantAttribute(), new VariableIntervalTimeVariantAttribute()); }
assertEquals(10.0, link.getFreespeed(Time.UNDEFINED_TIME), EPSILON); assertEquals(10.0, NetworkUtils.getFreespeedTravelTime(link, Time.UNDEFINED_TIME), EPSILON); change.addLink(link); change.setFreespeedChange(new ChangeValue(ChangeType.ABSOLUTE_IN_SI_UNITS, 20)); link.applyEvent(change); assertEquals(10.0, link.getFreespeed(Time.UNDEFINED_TIME), EPSILON); // at undefined time, return base value assertEquals(10.0, link.getFreespeed(7*3600.0 - 1.0), EPSILON); // one second before change, still base value assertEquals(10.0, link.getFreespeed(7*3600.0 - 0.1), EPSILON); // just before change, still base value assertEquals(20.0, link.getFreespeed(7*3600.0), EPSILON); // just on time of change, new value assertEquals(20.0, link.getFreespeed(8*3600.0), EPSILON); // some time later, still new value