private void assignOpeningTimes() { Set<String> missingActTypes = new HashSet<>(); for (ActivityFacility af : this.facilities.getFacilities().values()) { for (ActivityOption ao : af.getActivityOptions().values()) { String actType = ao.getType(); ActivityParams params = this.planCalcScoreConfigGroup.getActivityParams(actType); if (params == null) { if (missingActTypes.add(actType)) { log.error("No information for activity type " + actType + " found in given configuration."); } } else { ao.addOpeningTime(new OpeningTimeImpl(params.getOpeningTime(), params.getClosingTime())); } } } }
public static double getTypicalDuration( final Scenario scenario, final Person person, final String type ) { final Double typicalDuration = (Double) scenario.getPopulation().getPersonAttributes().getAttribute( person.getId().toString(), "typicalDuration_"+type ); if ( typicalDuration != null ) return typicalDuration.doubleValue(); final ActivityParams params = scenario.getConfig().planCalcScore().getActivityParams( type ); if ( params == null ) { //throw new RuntimeException( "could not find typical duration for Person "+person.getId()+" for type "+type ); // not that nice, but needed for agents that might not have a preference. BeingTogetherScoring knows how to handle that return Double.NEGATIVE_INFINITY; } return params.getTypicalDuration(); }
@Test public void testAddActivityParams() { PlanCalcScoreConfigGroup c = new PlanCalcScoreConfigGroup(); Assert.assertNull(c.getActivityParams("type1")); // Assert.assertEquals(0, c.getActivityParams().size()); Assert.assertEquals(6, c.getActivityParams().size()); // yyyyyy see PlanCalcScoreConfigGroup, where I am currently adding interaction activities hard-wired. kai, feb'16 // yyyyyy and now also the "dummy" activity. kai, jul'17 ActivityParams ap = new ActivityParams("type1"); c.addActivityParams(ap); Assert.assertEquals(ap, c.getActivityParams("type1")); // Assert.assertEquals(1, c.getActivityParams().size()); Assert.assertEquals(7, c.getActivityParams().size()); // yyyyyy see PlanCalcScoreConfigGroup, where I am currently adding interaction activities hard-wired. kai, feb'16 // yyyyyy and now also the "dummy" activity. kai, jul'17 }
ActivityParams ptAct = c.planCalcScore().getActivityParams(PtConstants.TRANSIT_ACTIVITY_TYPE) ; if ( ptAct != null ) {
private void readPrefs() { String prefsFileName = this.dccg.getPrefsFile(); if (prefsFileName != null) { ObjectAttributesXmlReader prefsReader = new ObjectAttributesXmlReader(this.prefsAttributes); try { prefsReader.readFile(prefsFileName); log.info("reading prefs attributes from: \n"+ prefsFileName); } catch (UncheckedIOException e) { // reading was not successful log.error("unsuccessful prefs reading from files!\n" + prefsFileName); } } else { log.warn("prefs are taken from the config and if available from the desires as there is no preferences file specified \n"); for (ActivityParams activityParams : this.scenario.getConfig().planCalcScore().getActivityParams()) { for (Person p : this.scenario.getPopulation().getPersons().values()) { prefsAttributes.putAttribute(p.getId().toString(), "typicalDuration_" + activityParams.getActivityType(), activityParams.getTypicalDuration()); prefsAttributes.putAttribute(p.getId().toString(), "latestStartTime_" + activityParams.getActivityType(), activityParams.getLatestStartTime()); prefsAttributes.putAttribute(p.getId().toString(), "earliestEndTime_" + activityParams.getActivityType(), activityParams.getEarliestEndTime()); prefsAttributes.putAttribute(p.getId().toString(), "minimalDuration_" + activityParams.getActivityType(), activityParams.getMinimalDuration()); } } } }
for (ActivityParams params : this.getActivityParams()) { if (params.isScoringThisActivityAtAll() && Time.isUndefinedTime(params.getTypicalDuration())) { throw new RuntimeException("In activity type=" + params.getActivityType()
/** * Test the performing part of the scoring function. */ @Test public void testPerforming() { Fixture f = new Fixture(); double perf = +6.0; double zeroUtilDurW = getZeroUtilDuration_hrs(3.0, 1.0); double zeroUtilDurH = getZeroUtilDuration_hrs(15.0, 1.0); f.config.planCalcScore().setPerforming_utils_hr(perf); if(typicalDurationComputation.equals(TypicalDurationScoreComputation.uniform)){ for(ActivityParams p : f.config.planCalcScore().getActivityParams()){ p.setTypicalDurationScoreComputation(TypicalDurationScoreComputation.uniform); } } assertEquals(perf * 3.0 * Math.log(2.5 / zeroUtilDurW) + perf * 3.0 * Math.log(2.75/zeroUtilDurW) + perf * 3.0 * Math.log(2.5/zeroUtilDurW) + perf * 15.0 * Math.log(14.75 / zeroUtilDurH), calcScore(f), EPSILON); // perf = +3.0; // f.config.planCalcScore().setPerforming_utils_hr(perf); // assertEquals(perf * 3.0 * Math.log(2.5 / zeroUtilDurW) // + perf * 3.0 * Math.log(2.75/zeroUtilDurW) // + perf * 3.0 * Math.log(2.5/zeroUtilDurW) // + perf * 15.0 * Math.log(14.75 / zeroUtilDurH), calcScore(f), EPSILON); }
f.config.planCalcScore().getActivityParams("h").setTypicalDuration(6.0 * 3600); for(ActivityParams p : f.config.planCalcScore().getActivityParams()){ p.setTypicalDurationScoreComputation(TypicalDurationScoreComputation.uniform);
/** * Test the performing part of the scoring function when an activity has a ClosingTime set. */ @Test public void testClosingTime() { Fixture f = new Fixture(); double perf = +6.0; f.config.planCalcScore().setPerforming_utils_hr(perf); double initialScore = calcScore(f); ActivityParams wParams = f.config.planCalcScore().getActivityParams("w"); wParams.setClosingTime(15*3600.0); // now the agent stays 1h too long at the LAST work activity double score = calcScore(f); // check the difference between 2.5 and 1.5 hours working assertEquals(perf * 3.0 * Math.log(2.5 / 1.5), initialScore - score, EPSILON); }
/** * Test the performing part of the scoring function when an activity has an OpeningTime set. */ @Test public void testOpeningTime() { Fixture f = new Fixture(); double perf = +6.0; f.config.planCalcScore().setPerforming_utils_hr(perf); double initialScore = calcScore(f); ActivityParams wParams = f.config.planCalcScore().getActivityParams("w"); wParams.setOpeningTime(8*3600.0); // now the agent arrives 30min early to the FIRST work activity and has to wait double score = calcScore(f); // check the difference between 2.5 and 2.0 hours of working assertEquals(perf * 3.0 * Math.log(2.5 / 2.0), initialScore - score, EPSILON); }
/** * Test the scoring function in regards to early departures. */ @Test public void testMinimumDuration() { Fixture f = new Fixture(); double disutility = -10.0; f.config.planCalcScore().setEarlyDeparture_utils_hr(disutility); ActivityParams wParams = f.config.planCalcScore().getActivityParams("w"); wParams.setMinimalDuration(3 * 3600.0); // require the agent to be 3 hours at every working activity // the agent overall works 1.25h too short assertEquals(disutility * 1.25, calcScore(f), EPSILON); }
f.config.planCalcScore().getActivityParams("h").setTypicalDuration(7.0 * 3600); f.config.planCalcScore().setPerforming_utils_hr(perf); for(ActivityParams p : f.config.planCalcScore().getActivityParams()){ p.setTypicalDurationScoreComputation(TypicalDurationScoreComputation.uniform);
/** * Test the scoring function in regards to early departures. */ @Test public void testEarlyDeparture() { Fixture f = new Fixture(); double disutility = -10.0; f.config.planCalcScore().setEarlyDeparture_utils_hr(disutility); ActivityParams wParams = f.config.planCalcScore().getActivityParams("w"); wParams.setEarliestEndTime(10.75 * 3600.0); // require the agent to work until 16:45 // the agent left 45mins too early assertEquals(disutility * 0.75, calcScore(f), EPSILON); }
/** * Test the scoring function in regards to late arrival. */ @Test public void testLateArrival() { Fixture f = new Fixture(); double disutility = -10.0; f.config.planCalcScore().setLateArrival_utils_hr(disutility); ActivityParams wParams = f.config.planCalcScore().getActivityParams("w"); wParams.setLatestStartTime(13 * 3600.0); // agent should start working latest at 13 o'clock // the agent arrived 30mins late assertEquals(disutility * 0.5, calcScore(f), EPSILON); }
for ( ActivityParams settings : initialGroup.getActivityParams() ) { final String suffix = r.nextBoolean() ? ""+ca++ : settings.getActivityType();
for(ActivityParams params : pcs.getActivityParams()){ params.setTypicalDurationScoreComputation(typicalDurationScoreComputation); double typicalDuration_s = pcs.getActivityParams("home").getTypicalDuration() ; double priority = 1. ; ActivityUtilityParameters.Builder builder = new ActivityUtilityParameters.Builder( pcs.getActivityParams("home") ) ; ActivityUtilityParameters params = builder.build() ; double zeroUtilityDurationHome_s = params.getZeroUtilityDuration_h() * 3600. ;
for(ActivityParams params : pcs.getActivityParams()){ params.setTypicalDurationScoreComputation(typicalDurationScoreComputation); double typicalDuration_s = pcs.getActivityParams("home").getTypicalDuration() ; double priority = 1. ; ActivityUtilityParameters.Builder builder = new ActivityUtilityParameters.Builder( pcs.getActivityParams("home") ) ; ActivityUtilityParameters params = builder.build() ; double zeroUtilityDurationHome_s = params.getZeroUtilityDuration_h() * 3600. ;
/** * Test the waiting part of the scoring function. */ @Test public void testWaitingTime() { Fixture f = new Fixture(); double waiting = -10.0; f.config.planCalcScore().setMarginalUtlOfWaiting_utils_hr(waiting); ActivityParams wParams = f.config.planCalcScore().getActivityParams("w"); wParams.setOpeningTime( 8*3600.0); // the agent arrives 30min early wParams.setClosingTime(15*3600.0); // the agent stays 1h too long // the agent spends 1.5h waiting at the work place assertEquals(waiting * 1.5, calcScore(f), EPSILON); }
for(ActivityParams params : pcs.getActivityParams()){ params.setTypicalDurationScoreComputation(typicalDurationScoreComputation); double typicalDuration_s = pcs.getActivityParams("home").getTypicalDuration() ; double priority = 1. ; ActivityUtilityParameters.Builder builder = new ActivityUtilityParameters.Builder( pcs.getActivityParams("home") ) ; ActivityUtilityParameters params = builder.build() ; double zeroUtilityDurationHome_s = params.getZeroUtilityDuration_h() * 3600. ;
for(ActivityParams p : f.config.planCalcScore().getActivityParams()){ p.setTypicalDurationScoreComputation(TypicalDurationScoreComputation.uniform); ActivityParams wParams = f.config.planCalcScore().getActivityParams("w"); wParams.setOpeningTime( 8*3600.0); // the agent arrives 30min early wParams.setClosingTime(15*3600.0); // the agent stays 1h too long