📄 scheduler.java
字号:
/* * (C) Copyright 2005 Davide Brugali, Marco Torchiano * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */package scheduler;import java.util.*;public class Scheduler { public static int STEPS = 80; private Problem problem = null; private int bestStep; // the index of the best performance iteration private double bestValue; // the value of the best performance/* P2 */ private ArrayList performances = new ArrayList(); public Scheduler() { }/* P2 */ public void reset() { bestStep = 0; bestValue = 1e9; problem.init(); }/* P2 */ public void setProblem(Problem problem) { this.problem = problem; bestStep = 0; bestValue = 1e9; problem.init();/* P2 */ performances.removeAll(performances); Iterator iterator = problem.getResources(); Resource resource; while(iterator.hasNext()) { iterator.next(); double perf[] = new double[STEPS]; performances.add(perf); }/* P2 */ } public int bestStep() { return bestStep; } public double bestValue() { return bestValue; } public double[] getPerformances(int i) { return (double[]) performances.get(i); } public void schedule(double gain) { Iterator iterator = problem.getResources(); Resource resource; while(iterator.hasNext()) { resource = (Resource) iterator.next(); resource.reset(); resource.setGain(gain); } // repeats the scheduling step 80 times for (int step = 0; step < STEPS; step++) { double totPerformance = 0.0; // every resource schedules its activities iterator = problem.getResources(); while(iterator.hasNext()) ((Resource) iterator.next()).schedule(); // evaluate the total performace/* P2 */ iterator = problem.getResources(); int i = 0; while(iterator.hasNext()) { double p[] = (double[]) performances.get(i++); p[step] = ((Resource) iterator.next()).getPerformance(); totPerformance += p[step]; }/* P2 */ // evaluates the performance of this scheduling step if (totPerformance < bestValue) { bestValue = totPerformance; // this is the best performance up to now, thus stores the solution iterator = problem.getResources(); while(iterator.hasNext()) ((Resource) iterator.next()).store(); bestStep = step; } } // restores the solution corresponding to the best performance step iterator = problem.getResources(); while(iterator.hasNext()) ((Resource) iterator.next()).restore(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -