Commit 0c7bd9c1 authored by Vladislav Kiselev's avatar Vladislav Kiselev

Main улучшен

parent ad5581f9
......@@ -16,16 +16,17 @@ public class Main {
private static final int DEFAULT_TIME_LIMIT_S = 3600;
private enum ConversionType {
Undefined ("", ""),
WithoutSplitting("Without splitting", "conversion_2.mzn"),
WithSplitting ("With splitting", "conversion_2_with_partial_cargo_operations.mzn"),
Greedy_v2 ("Greedy v2", "conversion_2_greedy_v2.mzn");
Undefined ("", (TaskCase t, Integer i) -> ""),
WithoutSplitting("Without splitting", Testing::solveTask_2),
WithSplitting ("With splitting", Testing::solveTaskWithPartialCargoOp),
Greedy ("Greedy", Testing::solveTaskWithGreedyConstraints),
Greedy_v2 ("Greedy v2", Testing::solveTaskWithGreedyConstraintsV2);
private final String text;
private final String constraintName;
ConversionType(String text, String constraintName) {
private final BiFunction<TaskCase, Integer, String> solver;
ConversionType(String text, BiFunction<TaskCase, Integer, String> solver) {
this.text = text;
this.constraintName = constraintName;
this.solver = solver;
}
public static ConversionType fromString(String text) {
for (ConversionType t : ConversionType.values()) {
......@@ -37,6 +38,18 @@ public class Main {
}
}
private static String undefinedTypeErrorMess(String undefType) {
StringBuilder s = new StringBuilder("Undefined conversion type - \"" + undefType + "\".\n");
ArrayList<String> values = new ArrayList<>();
for (ConversionType conversionType : ConversionType.values()) {
if (! conversionType.equals(ConversionType.Undefined)) {
values.add("\"" + conversionType.text + "\"");
}
}
s.append("Conversion type can be one of ").append(String.join(", ", values)).append(".");
return s.toString();
}
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("To few arguments.");
......@@ -63,25 +76,11 @@ public class Main {
} else {
ConversionType t = (args.length == 2) ? ConversionType.WithoutSplitting
: ConversionType.fromString(args[2]);
if (t.equals(ConversionType.Undefined)) {
System.out.println("Undefined conversion type - \"" + args[2] + "\".");
ArrayList<String> values = new ArrayList<>();
for (ConversionType conversionType : ConversionType.values()) {
if (! conversionType.equals(ConversionType.Undefined)) {
values.add("\"" + conversionType.text + "\"");
}
}
System.out.print("Conversion type can be one of " + String.join(", ", values) + ".");
System.out.println(undefinedTypeErrorMess(args[2]));
return;
}
error = solveTask(
task,
t.constraintName,
Task::portToMiniZinc_2,
MZnResultsResolver::resolveMiniZincResults,
DEFAULT_TIME_LIMIT_S);
error = t.solver.apply(task, DEFAULT_TIME_LIMIT_S);
}
long finish = System.currentTimeMillis();
......@@ -136,19 +135,13 @@ public class Main {
break;
}
case "debug" : {
debug(Testing::solveTask_2, DEFAULT_TIME_LIMIT_S);
break;
}
case "debug 2" : {
debug(Testing::solveTaskWithPartialCargoOp, DEFAULT_TIME_LIMIT_S);
break;
}
case "debug greedy" : {
debug(Testing::solveTaskWithGreedyConstraints, DEFAULT_TIME_LIMIT_S);
break;
ConversionType t = (args.length == 2) ? ConversionType.WithoutSplitting
: ConversionType.fromString(args[2]);
if (t.equals(ConversionType.Undefined)) {
System.out.println(undefinedTypeErrorMess(args[2]));
return;
}
case "debug greedy v2" : {
debug(Testing::solveTaskWithGreedyConstraintsV2, DEFAULT_TIME_LIMIT_S);
debug(t.solver, DEFAULT_TIME_LIMIT_S);
break;
}
case "debug read-write" : {
......@@ -156,14 +149,18 @@ public class Main {
break;
}
case "testing" :
ConversionType t = (args.length == 2) ? ConversionType.WithoutSplitting
: ConversionType.fromString(args[2]);
if (t.equals(ConversionType.Undefined)) {
System.out.println(undefinedTypeErrorMess(args[2]));
return;
}
testGroup("with_typing", t.solver, DEFAULT_TIME_LIMIT_S);
test_2(DEFAULT_TIME_LIMIT_S);
break;
case "test_experiment":
testGroup("experiments", Testing::solveTask_2, DEFAULT_TIME_LIMIT_S);
break;
case "testing_with_partial_op":
testWithPartialOp(DEFAULT_TIME_LIMIT_S);
break;
case "different_parameters":
try {
testingWithDiffParameters(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment