From 0c7bd9c1efc1621dc255a9ff9f6d66583add3816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=81=D0=B5=D0=BB=D1=91=D0=B2=20=D0=92=D0=BB?= =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2?= Date: Mon, 8 Jul 2019 15:12:14 +0300 Subject: [PATCH] =?UTF-8?q?Main=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5?= =?UTF-8?q?=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/inport/Main.java | 75 +++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/src/inport/Main.java b/src/inport/Main.java index 138de18..d69cc35 100644 --- a/src/inport/Main.java +++ b/src/inport/Main.java @@ -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 solver; + ConversionType(String text, BiFunction 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 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 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; - } - case "debug greedy v2" : { - debug(Testing::solveTaskWithGreedyConstraintsV2, DEFAULT_TIME_LIMIT_S); + ConversionType t = (args.length == 2) ? ConversionType.WithoutSplitting + : ConversionType.fromString(args[2]); + if (t.equals(ConversionType.Undefined)) { + System.out.println(undefinedTypeErrorMess(args[2])); + return; + } + 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( -- GitLab