public int GetNextIdByF(int studentId, String testTime, double cita) throws SQLException { |
ProblemControl pc = new ProblemControl(); |
int IDMAX = 691; |
double = 20.00; |
int = 0; |
// Cooling parameter table |
int MarkovLength = 25; |
double Temperature = 100; |
double Tolerance = ; |
int PreId, NextId; |
int BestId; // Optimal solution |
Random random = new Random(); |
PreId = pc.GetRandomProblemId(); |
BestId = PreId; |
do { |
Temperature = ; |
++; |
for (int = 0; < MarkovLength; ++) { |
// (1) Selected solutions from the neighborhood structure |
do { |
NextId = pc.GetRandomProblemId(); |
if (NextId == PreId) { |
NextId = pc.GetRandomProblemId(); |
} |
} while (!(NextId ≥ 0 && NextId ≤ IDMAX)); |
// (2) Whether the global optimum solution? |
if (pc.ObjectFunction(studentId, testTime, BestId, cita) |
≤ pc.ObjectFunction(studentId, testTime, NextId, cita)) { |
PreBestId = BestId; // retain the previous Optimal solution |
BestId = NextId; //the new optimal solution; |
} |
// (3) Metropolis process |
if (pc.ObjectFunction(studentId, testTime, PreId, cita) |
− pc.ObjectFunction(studentId, testTime, NextId, cita) < 0) { |
PreId = NextId; |
} else { |
double change = −1 * (pc.ObjectFunction(studentId, testTime, PreId, cita) |
− pc.ObjectFunction(studentId, testTime, NextId, cita)) / Temperature; |
if (Math.exp(change) > random.nextDouble()) { |
PreId = NextId; |
} else { |
Not accepted, save the original solution |
} |
} |
} //According to Metropolis acceptance criteria to judge |
} |
while (Math.abs(pc.ObjectFunction(studentId, testTime, BestId, cita) |
− pc.ObjectFunction(studentId, testTime, PreBestId, cita)) |
> Tolerance && Temperature ≥ 0); // Termination condition |
return BestId; // Return to the optimal solution |
} |