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.HashSet;
027    
028    import se.liu.ida.critiquer.activities.Activity;
029    import se.liu.ida.critiquer.activities.ActivityUtils;
030    import se.liu.ida.critiquer.activities.parameters.LocationParameter;
031    import se.liu.ida.critiquer.resources.Agent;
032    
033    public class RoadBlockActivity extends Activity {
034    
035            /**
036             * 
037             */
038            private static final long serialVersionUID = 1L;
039    
040            private static int numActivities;
041    
042            public RoadBlockActivity(Activity parent) {
043                    super("Block roads", parent);
044            }
045    
046            /*
047             * (non-Javadoc)
048             * 
049             * @see se.liu.ida.critiquer.activities.Activity#addDefaultParams()
050             */
051            @Override
052            public void addDefaultParams() {
053                    super.addDefaultParams();
054                    addParam(new LocationParameter(LocationParameter.Type.STATIC_LOC,"road block location", this));
055            }
056    
057            /**
058             * It takes the amount of time of the fastest agent to perform this
059             * operation.
060             */
061            @Override
062            public long calculateTimeToComplete() {
063                    long timeToComplete = Long.MAX_VALUE;
064                    // time in minutes
065                    HashSet<Agent> agentsInActivity = ActivityUtils.getAgentsInActivity(this);
066                    if (!agentsInActivity.isEmpty()) {
067                            for (Agent agent : agentsInActivity) {
068                                    try {
069                                            timeToComplete = Math.min(timeToComplete, agent.perform(RoadBlockActivity.class, this, null));
070                                            /**
071                                             * If an agent is unsuitable for a certain type of operation, we
072                                             * catch that exception here
073                                             */
074                                    } catch (UnsupportedOperationException e) {
075                                            System.err.println(e.getMessage());
076                                    }
077                            }
078                    } else {
079                            timeToComplete=0;
080                    }
081                     
082                    return timeToComplete;
083    
084            }
085    
086    
087    
088            @Override
089            public int getNumActivities() {
090                    return RoadBlockActivity.numActivities++;
091            }
092    
093    }