@@ -0,0 +1,2260 @@
+/*%0A * Copyright 2016 Will Knez %3Cwbknez.dev@gmail.com%3E%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.solsticesquared.schelling.task;%0A%0Aimport com.solsticesquared.schelling.SchellingExplorer;%0Aimport sim.engine.SimState;%0Aimport sim.engine.Steppable;%0A%0A/**%0A * Represents a task, implemented as a %7B@link Steppable%7D, that determines%0A * whether or not a simulation has been allowed to execute for more than an%0A * arbitrary number of steps and, if so, forces it to stop.%0A *%0A * %3Cp%3E%0A *     In addition, this task can also stop a simulation if the number of%0A *     %22unhappy%22 agents is zero.  Please note that this is disabled by%0A *     default but can be activated via the user-interface options.%0A * %3C/p%3E%0A */%0Apublic class StopConditionTask implements Steppable %7B%0A%0A    /**%0A     * The current number of executed steps.%0A     *%0A     * %3Cp%3E%0A     *     This is intentionally kept separate from MASON's internal schedule%0A     *     counter to avoid potential conflicts.%0A     * %3C/p%3E%0A     */%0A    private int internalCounter;%0A%0A    @Override%0A    public void step(SimState simState) %7B%0A        final SchellingExplorer model = (SchellingExplorer)simState;%0A%0A        // Increment the number of steps we've taken.%0A        this.internalCounter++;%0A%0A        // Determine the status of both stopping conditions.%0A        final boolean mustStop =%0A                this.internalCounter %3E= model.getParameters().getMaximumSteps();%0A        final boolean shouldStop =%0A                model.getParameters().getStopOnEquilibrium()%0A                  && model.getMovementList().isEmpty();%0A%0A        // Compare to the maximum number of steps allowed.%0A        if(mustStop %7C%7C shouldStop) %7B%0A            // Force the simulation to stop.%0A            model.finish();%0A        %7D%0A    %7D%0A%7D%0A

Add task that stops the simulation if conditions are met to do so.