我在运行这个模拟CPU工作的java代码时遇到问题。它使用循环法为进程提供服务。我从引用中获取了代码,这正是我需要的,但不幸的是它没有运行并抛出此异常:
Exception in thread "main" java.lang.NoClassDefFoundError: optimization/Lmder_fcn
at umontreal.iro.lecuyer.probdist.StudentDist.inverseF(StudentDist.java:278)
at umontreal.iro.lecuyer.stat.Tally.confidenceIntervalStudent(Tally.java:294)
at umontreal.iro.lecuyer.stat.Tally.formatCIStudent(Tally.java:359)
at umontreal.iro.lecuyer.stat.Tally.report(Tally.java:497)
这是代码:
package timeshared;
import umontreal.iro.lecuyer.simevents.*;
import umontreal.iro.lecuyer.simprocs.*;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.randvar.*;
import umontreal.iro.lecuyer.stat.Tally;
import java.io.*;
public class RoundRobinQueue {
int NumberOfTermainals = 20; // Number of terminals.
double q; // Quantum size.
double overhead = 0.001; // Amount of overhead (h).
double meanThinkingTime = 5.0; // Mean thinking time.
double alpha = 0.5; // Parameters of the Weibull service times.
double lambda = 1.0; // ''
double delta = 0.0; // ''
int N = 1100; // Total number of tasks to simulate.
int N0 = 100; // Number of tasks for warmup.
int NumberOfTasks; // Number of tasks ended so far.
RandomStream streamThink = new MRG32k3a();
RandomVariateGen genThink = new ExponentialGen(streamThink, 1.0 / meanThinkingTime);
RandomStream streamServ = new MRG32k3a("Gen. for service requirements");
RandomVariateGen genServ = new WeibullGen(streamServ, alpha, lambda, delta);
Resource server = new Resource(1, "The server");
Tally meanInRep = new Tally("Average for current run");
Tally statDiff = new Tally("Diff. on mean response times");
class Terminal extends SimProcess {
public void actions() {
double arrivTime; // Arrival time of current request.
double timeNeeded; // Server's time still needed for it.
while (NumberOfTasks < N) {
delay(genThink.nextDouble());
arrivTime = Sim.time();
timeNeeded = genServ.nextDouble();
while (timeNeeded > q) {
server.request(1);
delay(q + overhead);
timeNeeded -= q;
server.release(1);
}
server.request(1); // Here, timeNeeded <= q.
delay(timeNeeded + overhead);
server.release(1);
NumberOfTasks++;
if (NumberOfTasks > N0) meanInRep.add(Sim.time() - arrivTime);
// Take the observation if warmup is over.
}
Sim.stop(); // N tasks have now completed.
}
}
private void simulOneRun() {
SimProcess.init();
server.init();
meanInRep.init();
NumberOfTasks = 0;
for (int i = 1; i <= NumberOfTermainals; i++)
new Terminal().schedule(0.0);
Sim.start();
}
// Simulate numRuns pairs of runs and prints a confidence interval
// on the difference of perf. for q sizes q1 and q2.
public void simulateConfigs(double numRuns, double q1, double q2) {
double mean1; // To memorize average for first configuration.
for (int rep = 0; rep < numRuns; rep++) {
q = q1;
simulOneRun();
mean1 = meanInRep.average();
streamThink.resetStartSubstream();
streamServ.resetStartSubstream();
q = q2;
simulOneRun();
statDiff.add(mean1 - meanInRep.average());
streamThink.resetNextSubstream();
streamServ.resetNextSubstream();
}
statDiff.setConfidenceIntervalStudent();
System.out.println(statDiff.report(0.9, 3));
}
public static void main(String[] args) {
new RoundRobinQueue().simulateConfigs(10, 0.1, 0.2);
}
}
答案 0 :(得分:1)
您在类路径中缺少几个jar文件。从文档看起来你需要以下罐子。 http://www-labs.iro.umontreal.ca/~simardr/ssj/examples/examples.pdf
colt.jar,Blas.jar,optimization.jar(特别针对您的问题),jfreechart- .jar和jcommon - .jar
答案 1 :(得分:0)
我修复了问题,该程序需要一个优化库here 工作,我添加了jar文件,它工作正常