001 /** 002 * planningtool - A Planning Tool with Critiquing Support. 003 * 004 * Copyright (C) 2006 olale 005 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU General Public License 008 * as published by the Free Software Foundation; either version 2 009 * of the License, or (at your option) any later version. 010 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 016 * You should have received a copy of the GNU General Public License 017 * along with this program; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 020 * Contact information: 021 * E-mail: olale@ida.liu.se 022 * olale@lysator.liu.se 023 */ 024 package se.liu.ida.critiquer.scenarios.standard; 025 026 import java.util.HashMap; 027 import java.util.HashSet; 028 import java.util.Vector; 029 030 import se.liu.ida.critiquer.activities.Activity; 031 import se.liu.ida.critiquer.activities.ActivityUtils; 032 import se.liu.ida.critiquer.activities.TransportationActivity; 033 import se.liu.ida.critiquer.activities.parameters.Location; 034 import se.liu.ida.critiquer.activities.parameters.LocationParameter; 035 import se.liu.ida.critiquer.activities.parameters.NumberSelectionParameter; 036 import se.liu.ida.critiquer.resources.Agent; 037 038 public class RecoverActivity extends Activity implements TransportationActivity { 039 040 /** 041 * 042 */ 043 private static final String NUMBER_INJURED = "number injured"; 044 /** 045 * 046 */ 047 private static final String PATIENTS = "patients"; 048 /** 049 * 050 */ 051 private static final String STARTING_LOCATION = "starting location"; 052 /** 053 * 054 */ 055 private static final String MEDICAL_FACILITY_LOCATION = "medical facility location"; 056 /** 057 * 058 */ 059 private static final long serialVersionUID = 1L; 060 private static int numActivities; 061 062 public RecoverActivity(Activity parent) { 063 super("Recover",parent); 064 } 065 066 /* (non-Javadoc) 067 * @see se.liu.ida.critiquer.activities.Activity#addDefaultParams() 068 */ 069 @Override 070 public void addDefaultParams() { 071 super.addDefaultParams(); 072 Vector<Integer> numbers = new Vector<Integer>(); 073 for (int i = 0; i < 10; i++) { 074 numbers.add(i); 075 } 076 final NumberSelectionParameter injuredSelector = new NumberSelectionParameter(this,NUMBER_INJURED,numbers,2); 077 ActivityUtils.createMissionTimeUpdater(injuredSelector); 078 addParam(injuredSelector); 079 addParam(new LocationParameter(LocationParameter.Type.ORIG_LOC,STARTING_LOCATION,this)); 080 addParam(new LocationParameter(LocationParameter.Type.DEST_LOC,MEDICAL_FACILITY_LOCATION,this)); 081 } 082 083 @Override 084 public long calculateTimeToComplete() { 085 // time in minutes 086 long totalTime=0; 087 long timeForRound=0; 088 HashMap<String, Integer> attributes = new HashMap<String,Integer>(); 089 attributes.put(PATIENTS,getInjured()); 090 091 HashSet<Agent> agents = ActivityUtils.getAgentsInActivity(this); 092 while (attributes.get(PATIENTS) > 0) { 093 // TODO: Change this to reflect that units need to go back to 094 // retrieve patients once more 095 timeForRound = 0; 096 097 for (Agent agent : agents) { 098 timeForRound = Math.max(timeForRound, agent.perform(RecoverActivity.class, this, attributes)); 099 if (attributes.get(PATIENTS) > 0) { 100 break; 101 } 102 } 103 totalTime += timeForRound; 104 105 } 106 107 return totalTime; 108 109 } 110 111 /** 112 * @return Returns the injured. 113 */ 114 public int getInjured() { 115 NumberSelectionParameter numberSelector = ActivityUtils.getParamByClassAndName(this, NumberSelectionParameter.class, NUMBER_INJURED); 116 int returnValue = 0; 117 returnValue = numberSelector.getValue(); 118 return returnValue; 119 } 120 121 @Override 122 public int getNumActivities() { 123 return RecoverActivity.numActivities++; 124 } 125 126 /* (non-Javadoc) 127 * @see se.liu.ida.critiquer.activities.TransportationActivity#getStart() 128 */ 129 public Location getStart() { 130 return ActivityUtils.getParamByClassAndName(this, LocationParameter.class, STARTING_LOCATION).getValue(); 131 } 132 133 /* (non-Javadoc) 134 * @see se.liu.ida.critiquer.activities.TransportationActivity#getEnd() 135 */ 136 public Location getEnd() { 137 return ActivityUtils.getParamByClassAndName(this, LocationParameter.class, MEDICAL_FACILITY_LOCATION).getValue(); 138 } 139 140 }