From 269a7f9870377087ccdd3a8190b8ee9c4be3a93f Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Sat, 4 Nov 2023 18:44:30 -0700 Subject: [PATCH] Optimize trace build, add trace sim code --- Benchmark/Craftimizer.Benchmark.csproj | 16 +++ Benchmark/Program.cs | 131 +++++++++++++++-------- Craftimizer.Test/Craftimizer.Test.csproj | 6 +- Simulator/Craftimizer.Simulator.csproj | 10 +- Solver/Craftimizer.Solver.csproj | 10 +- 5 files changed, 118 insertions(+), 55 deletions(-) diff --git a/Benchmark/Craftimizer.Benchmark.csproj b/Benchmark/Craftimizer.Benchmark.csproj index e255672..dde07aa 100644 --- a/Benchmark/Craftimizer.Benchmark.csproj +++ b/Benchmark/Craftimizer.Benchmark.csproj @@ -9,6 +9,12 @@ Debug;Release;Trace + + + + + + @@ -22,4 +28,14 @@ + + + $(DefineConstants);IS_DETERMINISTIC + + + + True + $(DefineConstants);IS_DETERMINISTIC;IS_TRACE + + diff --git a/Benchmark/Program.cs b/Benchmark/Program.cs index 397686c..280e367 100644 --- a/Benchmark/Program.cs +++ b/Benchmark/Program.cs @@ -1,4 +1,3 @@ -using BenchmarkDotNet.Running; using Craftimizer.Simulator; using Craftimizer.Simulator.Actions; using Craftimizer.Solver; @@ -10,19 +9,16 @@ internal static class Program { private static async Task Main(string[] args) { +#if !IS_TRACE Environment.SetEnvironmentVariable("IS_BENCH", "1"); - BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); - return; - - //TypeLayout.PrintLayout>(true); - //return; - + BenchmarkDotNet.Running.BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); +#else var input = new SimulationInput( - new CharacterStats + new() { - Craftsmanship = 4078, - Control = 3897, - CP = 704, + Craftsmanship = 4041, + Control = 3905, + CP = 609, Level = 90, CanUseManipulation = true, HasSplendorousBuff = false, @@ -44,47 +40,90 @@ internal static class Program ProgressDivider = 130, } ); - var config = new SolverConfig() { - Iterations = 100_000, - ForkCount = 32, - FurcatedActionCount = 16, - MaxStepCount = 30, + Algorithm = SolverAlgorithm.Stepwise, + Iterations = 30000 }; - - var sim = new SimulatorNoRandom(new(input)); - (_, var state) = sim.Execute(new(input), ActionType.MuscleMemory); - (_, state) = sim.Execute(state, ActionType.PrudentTouch); - //(_, state) = sim.Execute(state, ActionType.Manipulation); - //(_, state) = sim.Execute(state, ActionType.Veneration); - //(_, state) = sim.Execute(state, ActionType.WasteNot); - //(_, state) = sim.Execute(state, ActionType.Groundwork); - //(_, state) = sim.Execute(state, ActionType.Groundwork); - //(_, state) = sim.Execute(state, ActionType.Groundwork); - //(_, state) = sim.Execute(state, ActionType.Innovation); - //(_, state) = sim.Execute(state, ActionType.PrudentTouch); - //(_, state) = sim.Execute(state, ActionType.AdvancedTouchCombo); - //(_, state) = sim.Execute(state, ActionType.Manipulation); - //(_, state) = sim.Execute(state, ActionType.Innovation); - //(_, state) = sim.Execute(state, ActionType.PrudentTouch); - //(_, state) = sim.Execute(state, ActionType.AdvancedTouchCombo); - //(_, state) = sim.Execute(state, ActionType.GreatStrides); - //(_, state) = sim.Execute(state, ActionType.Innovation); - //(_, state) = sim.Execute(state, ActionType.FocusedTouchCombo); - //(_, state) = sim.Execute(state, ActionType.GreatStrides); - //(_, state) = sim.Execute(state, ActionType.ByregotsBlessing); - //(_, state) = sim.Execute(state, ActionType.CarefulSynthesis); - //(_, state) = sim.Execute(state, ActionType.CarefulSynthesis); - - Console.WriteLine($"{state.Quality} {state.CP} {state.Progress} {state.Durability}"); - //return; - var solver = new Solver.Solver(config, state); - solver.OnLog += Console.WriteLine; - solver.OnNewAction += s => Console.WriteLine(s); + var solver = new Solver.Solver(config, new(input)); + solver.OnNewAction += s => Console.WriteLine($">{s}"); solver.Start(); var (_, s) = await solver.GetTask().ConfigureAwait(false); Console.WriteLine($"Qual: {s.Quality}/{s.Input.Recipe.MaxQuality}"); +#endif + return; + + ////TypeLayout.PrintLayout>(true); + ////return; + + //var input = new SimulationInput( + // new CharacterStats + // { + // Craftsmanship = 4078, + // Control = 3897, + // CP = 704, + // Level = 90, + // CanUseManipulation = true, + // HasSplendorousBuff = false, + // IsSpecialist = false, + // CLvl = 560, + // }, + // new RecipeInfo() + // { + // IsExpert = false, + // ClassJobLevel = 90, + // RLvl = 640, + // ConditionsFlag = 15, + // MaxDurability = 70, + // MaxQuality = 14040, + // MaxProgress = 6600, + // QualityModifier = 70, + // QualityDivider = 115, + // ProgressModifier = 80, + // ProgressDivider = 130, + // } + //); + + //var config = new SolverConfig() + //{ + // Iterations = 100_000, + // ForkCount = 32, + // FurcatedActionCount = 16, + // MaxStepCount = 30, + //}; + + //var sim = new SimulatorNoRandom(new(input)); + //(_, var state) = sim.Execute(new(input), ActionType.MuscleMemory); + //(_, state) = sim.Execute(state, ActionType.PrudentTouch); + ////(_, state) = sim.Execute(state, ActionType.Manipulation); + ////(_, state) = sim.Execute(state, ActionType.Veneration); + ////(_, state) = sim.Execute(state, ActionType.WasteNot); + ////(_, state) = sim.Execute(state, ActionType.Groundwork); + ////(_, state) = sim.Execute(state, ActionType.Groundwork); + ////(_, state) = sim.Execute(state, ActionType.Groundwork); + ////(_, state) = sim.Execute(state, ActionType.Innovation); + ////(_, state) = sim.Execute(state, ActionType.PrudentTouch); + ////(_, state) = sim.Execute(state, ActionType.AdvancedTouchCombo); + ////(_, state) = sim.Execute(state, ActionType.Manipulation); + ////(_, state) = sim.Execute(state, ActionType.Innovation); + ////(_, state) = sim.Execute(state, ActionType.PrudentTouch); + ////(_, state) = sim.Execute(state, ActionType.AdvancedTouchCombo); + ////(_, state) = sim.Execute(state, ActionType.GreatStrides); + ////(_, state) = sim.Execute(state, ActionType.Innovation); + ////(_, state) = sim.Execute(state, ActionType.FocusedTouchCombo); + ////(_, state) = sim.Execute(state, ActionType.GreatStrides); + ////(_, state) = sim.Execute(state, ActionType.ByregotsBlessing); + ////(_, state) = sim.Execute(state, ActionType.CarefulSynthesis); + ////(_, state) = sim.Execute(state, ActionType.CarefulSynthesis); + + //Console.WriteLine($"{state.Quality} {state.CP} {state.Progress} {state.Durability}"); + ////return; + //var solver = new Solver.Solver(config, state); + //solver.OnLog += Console.WriteLine; + //solver.OnNewAction += s => Console.WriteLine(s); + //solver.Start(); + //var (_, s) = await solver.GetTask().ConfigureAwait(false); + //Console.WriteLine($"Qual: {s.Quality}/{s.Input.Recipe.MaxQuality}"); } private static void Benchmark(Func search) diff --git a/Craftimizer.Test/Craftimizer.Test.csproj b/Craftimizer.Test/Craftimizer.Test.csproj index f2d7fde..520abba 100644 --- a/Craftimizer.Test/Craftimizer.Test.csproj +++ b/Craftimizer.Test/Craftimizer.Test.csproj @@ -22,9 +22,9 @@ - - - $(DefineConstants);IS_DETERMINISTIC + + + $(DefineConstants);IS_DETERMINISTIC diff --git a/Simulator/Craftimizer.Simulator.csproj b/Simulator/Craftimizer.Simulator.csproj index da4e1c5..908f912 100644 --- a/Simulator/Craftimizer.Simulator.csproj +++ b/Simulator/Craftimizer.Simulator.csproj @@ -15,9 +15,13 @@ - - $(DefineConstants);IS_DETERMINISTIC - $(DefineConstants);IS_DETERMINISTIC;IS_TRACE + + $(DefineConstants);IS_DETERMINISTIC + + + + True + $(DefineConstants);IS_DETERMINISTIC;IS_TRACE diff --git a/Solver/Craftimizer.Solver.csproj b/Solver/Craftimizer.Solver.csproj index 0779688..9be317b 100644 --- a/Solver/Craftimizer.Solver.csproj +++ b/Solver/Craftimizer.Solver.csproj @@ -20,9 +20,13 @@ - - $(DefineConstants);IS_DETERMINISTIC - $(DefineConstants);IS_DETERMINISTIC;IS_TRACE + + $(DefineConstants);IS_DETERMINISTIC + + + + True + $(DefineConstants);IS_DETERMINISTIC;IS_TRACE