private static void Main(string[] args) { var modelName = "FR001"; //var modelName = "FA001"; var srcModel = new TModel($"Data/Problems/{modelName}_src.mdl"); var tgtModel = new TModel($"Data/Problems/{modelName}_tgt.mdl"); //var srcModel = TModel.MakeEmpty(tgtModel.Name, tgtModel.R); //var tgtModel = TModel.MakeEmpty(srcModel.Name, srcModel.R); void TestStrategy(IStrategy strategy, bool saveTrace = false) { Console.WriteLine($"=== {strategy.Name}"); try { var trace = strategy.MakeTrace(srcModel, tgtModel); if (saveTrace) { File.WriteAllBytes("trace.nbt", TraceSerializer.Serialize(trace)); } if (trace == null) { Console.WriteLine(" empty trace"); return; } var state = new TState(srcModel); var reader = new TCommandsReader(trace); while (!reader.AtEnd()) { state.Step(reader); } Console.WriteLine(state.HasValidFinalState(tgtModel)); Console.WriteLine(state.Energy); } catch (Exception e) { Console.Write($"BROKENL {e}"); } } //TestStrategy(new DumpCubeStrategy()); //TestStrategy(new DumpCubeStrategy(), true); TestStrategy(new TTraceReaderStrategy($"data/DefaultTraces")); TestStrategy(new BfsStrategy(), true); }
private (long?energy, List <ICommand> commands) RunStrategy(Task task, IStrategy strategy, StreamWriter writer) { writer.Write($" {strategy.Name}: "); try { var commands = strategy.MakeTrace(task.Src, task.Tgt); if (commands == null) { return(null, null); } var state = new TState(task.Src); var step = 0; var commandsReader = new TCommandsReader(commands); while (!commandsReader.AtEnd()) { state.Step(commandsReader); step += 1; if (step % 1000000 == 0) { writer.Write("."); } } writer.Write(state.Energy); if (!state.HasValidFinalState(task.Tgt)) { writer.WriteLine(" !!FAIL!! "); return(null, null); } writer.WriteLine(); return(state.Energy, commands); } catch (Exception e) { writer.WriteLine($"exception: {e}"); return(null, null); } }