编程语言
首页 > 编程语言> > java踩雷日记--new

java踩雷日记--new

作者:互联网

java踩雷日记--new

觉得有用的话,欢迎一起讨论相互学习~Follow Me

1.数组元素中元素没有new导致数组为空

SolutionSet[] Donminant_pop;
Donminant_pop = new SolutionSet[NUMTASK];
Solution newSolution = new Solution(problemSet_);
B_pop[taskID].add(newSolution);
 B_pop[taskID] = new SolutionSet(ND_eachtask);

2.要用的对象要一次性new完,最好不要在调用的过程中或者循环的工程中重复new出新的对象

// Create the initial solutionSet B0
       for (int taskID = 0; taskID < NUMTASK; taskID++) {
           //初始化所有pop
           for (int popindex = 0; popindex < ND_eachtask; popindex++) {
               Solution newSolution = new Solution(problemSet_);
               problemSet_.get(taskID).evaluate(newSolution);
               problemSet_.get(taskID).evaluateConstraints(newSolution);
               evaluations++;
               // 初始建立种群时,为每个个体随机分配一个合适的任务即SkillFactor
               newSolution.setSkillFactor(taskID);
               B_pop[taskID] = new SolutionSet(ND_eachtask);
               B_pop[taskID].add(newSolution);
           }
       }
// Create the initial solutionSet B0
       for (int taskID = 0; taskID < NUMTASK; taskID++) {
           //初始化所有pop
           B_pop[taskID] = new SolutionSet(ND_eachtask);
           for (int popindex = 0; popindex < ND_eachtask; popindex++) {
               Solution newSolution = new Solution(problemSet_);
               problemSet_.get(taskID).evaluate(newSolution);
               problemSet_.get(taskID).evaluateConstraints(newSolution);
               evaluations++;
               // 初始建立种群时,为每个个体随机分配一个合适的任务即SkillFactor
               newSolution.setSkillFactor(taskID);
               B_pop[taskID].add(newSolution);
           }
       }

标签:java,problemSet,元素,pop,taskID,new,newSolution,日记
来源: https://www.cnblogs.com/cloud-ken/p/12103059.html