我在以下问题的代码中遇到了麻烦:Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive
您可以看一下代码并提出建议,非常感谢您的帮助。
Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive
at java.util.Random.nextInt(Random.java:388)
at vlslsfjs.util.RandomSolutionGenerator.generate(RandomSolutionGenerator.java:41)
at vlslsfjs.Run.main(Run.java:37)
C:\Users\Administrator\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
我的代码是
public class RandomSolutionGenerator {
static public final int FORCE_MIN_SIZE = 1;
static public final int FORCE_JOB_SIZE = 2;
public static LS2Solution generate(LS2Problem problem) {
return generate(problem, -1);
}
public static LS2Solution generate(LS2Problem problem, int forceSize) {
Random r = new Random();
Map<Integer, Double> opUIdToSublotSize = new HashMap<>();
Map<Integer, Integer> opUIdToMachId = new HashMap<>();
List<Integer> pwr = new ArrayList<>();
int j = 0;
for (LS2Job job : problem.getJobs()) {
for (LS2Operation op : job.getOperations()) {
List<Integer> avMachIds = new ArrayList<>(op.getAvMachineIds());
int ind = r.nextInt(avMachIds.size());
opUIdToMachId.put(op.getOpUId(), avMachIds.get(ind));
double slSize = op.getMinSize()
+ (op.getMaxSize() - op.getMinSize()) * r.nextDouble();
if (forceSize == FORCE_MIN_SIZE) {
slSize = op.getMinSize();
} else if (forceSize == FORCE_JOB_SIZE) {
slSize = job.getSize();
}
opUIdToSublotSize.put(op.getOpUId(), slSize);
}
for (int i = 0; i < job.getOperations().size(); ++i) {
pwr.add(j);
}
j++;
}
Collections.shuffle(pwr);
Map<Integer, List<Integer>> machIdToOpUIds = new HashMap<>();
int[] jobIndToOpInd = new int[problem.getJobs().size()];
for (int jobInd : pwr) {
int opInd = jobIndToOpInd[jobInd]++;
LS2Job job = problem.getJobs().get(jobInd);
LS2Operation op = job.getOperations().get(opInd);
int opUId = op.getOpUId();
int n = (int) Math.ceil(1.0 * job.getSize() / opUIdToSublotSize.get(op.getOpUId()));
int machId = opUIdToMachId.get(opUId);
List<Integer> opUIds = machIdToOpUIds.get(machId);
if (opUIds == null) {
opUIds = new ArrayList<>();
machIdToOpUIds.put(machId, opUIds);
}
for (int i = 0; i < n; ++i) {
opUIds.add(opUId);
}
}
return new LS2Solution(opUIdToSublotSize, machIdToOpUIds);
}
}