package hu.u_szeged.nbo.client.model;
import hu.u_szeged.nbo.client.solver.ResourceAllocationSolverThread;
import java.util.HashMap;
public class ResourceAllocation extends Model {
private static final long serialVersionUID = 1358187536394745614L;
private String algorithm;
private HashMap<String, String> algParams;
private ResourceAllocationSolverThread solver;
public static String[] descriptorFiles = {
"efo_igenyek.txt", "elemi_munkak.txt",
"eroforrasok.txt", "forgalmi_idoszakok.txt",
"helyek.txt", "megf_eng.txt",
"muszakok.txt", "utazasi_idok.txt", "kiindulas.txt"
};
public static String[] algorithms = { "best",
"greedy1_delta1", "greedy1_delta2",
"greedy1_delta3", "greedy1_delta4",
"greedy1_delta4_mod1", "greedy1_delta4_mod2",
"greedy1_delta4_mod3", "greedy2", "greedy2mod",
"greedy3_delta1", "greedy3_delta2",
"greedy3_delta3", "greedy3_delta4",
"greedy4", "brute_force", "reschedule"
} ;
public ResourceAllocation(String name, String user, HashMap<String, String> data) {
super(name, user, data);
checkType();
this.algorithm = algorithms[0];
this.algParams = new HashMap<String, String>();
this.uniqueID = this.hashCode();
updateSummary();
}
public void updateSummary() {
long time;
if (isStarted())
time = ((System.currentTimeMillis() - this.startTimeMillis));
else
time = 0;
this.summary = "Summary of problem:\n-------------------\n"
+ "\nName: " + name
+ "\nType: Resource allocation"
+ "\nAlgorithm: " + (this.algorithm.equals("best")
? "all, selecting best result"
: this.algorithm) + ", parameters: " + this.algParams
+ "\nStatus: " + this.getStateString()
+ "\n\nUnique hash: " + this.uniqueID
+ "\n\nTime: " + time / 1000 + " seconds.";
}
public void solve() {
solver = new ResourceAllocationSolverThread(this);
solver.start();
}
public String getAlgorithm() {
return this.algorithm;
}
public ResourceAllocationSolverThread getSolverThread() {
return this.solver;
}
public int getAlgorithmIndex(String alg) {
int index = 0;
for (index = 0; index < algorithms.length; index++) {
if (alg.equals(algorithms[index])) {
return index;
}
}
return -1;
}
public void setState(int newState) {
this.state |= newState;
this.updateSummary();
}
public void setAlgorithm(String algorithm) {
this.algorithm = algorithm;
this.updateSummary();
}
public void addAlgParam(String key, String value) {
this.algParams.remove(key);
this.algParams.put(key, value);
this.updateSummary();
}
public HashMap<String, String> getAlgParams() {
return this.algParams;
}
public void clear() {
this.algorithm = algorithms[0];
this.log = null;
this.solution.clear();
this.clearStates();
this.updateSummary();
}
private void checkType() {
this.type = RES_ALLOC;
}
}