初期化されていない計画値の計画エンティティをソリューションに設定することは可能ですか?初期化されていない計画値[エラー]
できれば、どうですか? :)
plzは、私はすべてが正常に動作nullでない計画変数で自分のコードを実行すると
:)私を助けて、私は、計画変数を設定せずに実行したとき、私は[Exception in thread "main" java.lang.NullPointerException
]
2012-02-14 17:32:08,119 [main] INFO Solver started: time spend (0), score (null), new best score (null), random seed (0).
Exception in thread "main" java.lang.NullPointerException
at org.drools.planner.core.score.definition.HardAndSoftScoreDefinition.calculateTimeGradient(HardAndSoftScoreDefinition.java:73)
at org.drools.planner.core.score.definition.HardAndSoftScoreDefinition.calculateTimeGradient(HardAndSoftScoreDefinition.java:25)
at org.drools.planner.core.termination.ScoreAttainedTermination.calculateSolverTimeGradient(ScoreAttainedTermination.java:52)
at org.drools.planner.core.termination.OrCompositeTermination.calculateSolverTimeGradient(OrCompositeTermination.java:70)
at org.drools.planner.core.termination.OrCompositeTermination.calculateSolverTimeGradient(OrCompositeTermination.java:70)
at org.drools.planner.core.termination.PhaseToSolverTerminationBridge.calculatePhaseTimeGradient(PhaseToSolverTerminationBridge.java:49)
at org.drools.planner.core.localsearch.DefaultLocalSearchSolverPhase.solve(DefaultLocalSearchSolverPhase.java:55)
at org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:166)
at org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:138)
at kz.bee.drools.planner.dating.DatingMain.start(DatingMain.java:58)
at kz.bee.drools.planner.dating.DatingMain.main(DatingMain.java:38)
を持っていますここに私のコードです:
package kz.bee.drools.planner.dating;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.xml.DOMConfigurator;
import org.drools.planner.config.XmlSolverConfigurer;
import org.drools.planner.core.Solver;
import org.drools.planner.core.event.BestSolutionChangedEvent;
import org.drools.planner.core.event.SolverEventListener;
import org.drools.planner.core.solution.Solution;
import org.drools.planner.core.solver.DefaultSolverScope;
public class DatingMain {
public static final int PERSON_PER_GENDER = 10;
public static final int HOUR_COUNT = 5;
public static final int TABLE_COUNT = 5;
public static final String SOLVER_CONFIG
= "/datingSolverConfig.xml";
private volatile Solver solver;
public DatingMain() {
DOMConfigurator.configure(getClass().getResource("/log4j-test.xml"));
}
public static void main(String[] args) {
DatingMain datingMain = new DatingMain();
datingMain.init();
datingMain.start();
}
private void init() {
XmlSolverConfigurer configurer = new XmlSolverConfigurer();
configurer.configure(SOLVER_CONFIG);
solver = configurer.buildSolver();
this.solver.addEventListener(new SolverEventListener() {
public void bestSolutionChanged(BestSolutionChangedEvent event) {
Dating dating = (Dating) solver.getBestSolution();
print(dating);
}
});
setPlanningProblem();
}
private void start() {
System.out.println("Start solving ...");
this.solver.solve();
Dating dating = (Dating) solver.getBestSolution();
System.out.println("Best solution:");
print(dating);
System.out.println("End solving.");
}
private void setPlanningProblem() {
List<Table> tableList = new ArrayList<Table>();
List<Hour> hourList = new ArrayList<Hour>();
List<Man> manList = new ArrayList<Man>();
List<Woman> womanList = new ArrayList<Woman>();
List<Meeting> meetingList = new ArrayList<Meeting>();
for(int i = 0; i < TABLE_COUNT; i++) {
Table t = new Table();
t.setId(Long.parseLong(""+i));
t.setNumber(i+10);
tableList.add(t);
}
for(int i = 0; i < HOUR_COUNT; i++) {
Hour h = new Hour();
h.setId(Long.parseLong(""+i));
h.setValue(i+1);
hourList.add(h);
}
for(int j = 0; j < PERSON_PER_GENDER; j++) {
Man m = new Man();
m.setId(Long.parseLong(""+j));
m.setName("Mr. #"+(j+1));
//m.setSuggestionList(new ArrayList<Long>());
if(j == 0) {
m.setSuggestionList(new ArrayList<Long>());
m.getSuggestionList().add(7L);
}
else if(j == 1) {
m.setSuggestionList(new ArrayList<Long>());
m.getSuggestionList().add(4L);
m.getSuggestionList().add(8L);
}
Woman w = new Woman();
w.setId(Long.parseLong(""+j));
w.setName("Ms. #"+(j+1));
manList.add(m);
womanList.add(w);
}
// manList.add(null); // womanList.add(null);
System.out.println("man & woman list size = " + manList.size() + " & " + womanList.size());
for(int j = 0; j < hourList.size(); j++) {
for(int i = 0; i < tableList.size(); i++) {
Meeting m = new Meeting();
m.setId(Long.parseLong(""+(j*hourList.size() + i)));
m.setTable(tableList.get(i));
m.setHour(hourList.get(j));
// m.setMan(null); // m.setWoman(null); //m.setMan(manList.get(i)); //m.setWoman(womanList.get((i+j)%10));あなたのsolverConfigで
meetingList.add(m);
}
}
Dating dating = new Dating();
dating.setId(Long.parseLong("1"));
dating.setTableList(tableList);
dating.setHourList(hourList);
dating.setManList(manList);
dating.setWomanList(womanList);
dating.setMeetingList(meetingList);
this.solver.setPlanningProblem((Solution) dating);
}
private void print(Dating dating) {
List<Meeting> meetingList = dating.getMeetingList();
System.out.println("===============================");
for(Meeting m : meetingList) {
System.out.printf("# %3s ",m.getId());
System.out.println(" t:" + m.getTable().getNumber() + " h:"+ m.getHour().getValue() + " m:"+m.getMan() + " w:" + m.getWoman());
}
System.out.println("Score (h/s): " + dating.getScore().getHardScore() + "/" + dating.getScore().getSoftScore() + " time: " + solver.getTimeMillisSpend());
System.out.println("===============================");
}
}
`
sovlerConfig-XML
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<solutionClass>kz.bee.drools.planner.dating.Dating</solutionClass>
<planningEntityClass>kz.bee.drools.planner.dating.Meeting</planningEntityClass>
<scoreDrl>/datingScoreRules.drl</scoreDrl>
<scoreDefinition>
<scoreDefinitionType>HARD_AND_SOFT</scoreDefinitionType>
</scoreDefinition>
<termination>
<terminationCompositionStyle>OR</terminationCompositionStyle>
<scoreAttained>0hard/1000soft</scoreAttained>
<maximumSecondsSpend>30</maximumSecondsSpend>
</termination>
<localSearch>
<selector>
<selector>
<moveFactoryClass>kz.bee.drools.planner.dating.solver.move.factory.ManChangeMoveFactory</moveFactoryClass>
</selector>
<selector>
<moveFactoryClass>kz.bee.drools.planner.dating.solver.move.factory.WomanChangeMoveFactory</moveFactoryClass>
</selector>
</selector>
<acceptor>
<completeSolutionTabuSize>1500</completeSolutionTabuSize>
</acceptor>
<forager>
<!-- <pickEarlyType>NEVER</pickEarlyType> -->
</forager>
</localSearch>
アイデアや提案はありますか? – Nurlan