示例#1
0
        public void SolutionModify()
        {
            var    item1 = new Item("a");
            var    item2 = new Item("b");
            Recipe r     = new Recipe("");

            r.AddIngredient(new ItemAmount(item1, 1));
            r.AddResult(new ItemAmount(item2, 1));
            r.CraftingCategory = "test";

            Building b = new Building("");

            b.AddCraftingCategory("test");
            b.IngredientCount = 4;
            b.ProductionSpeed = 1;

            Library l = new Library();

            l.AddItem(item1);
            l.AddItem(item2);
            l.AddRecipe(r);
            l.AddBuilding(b);
            l.Initialize();

            var coarseGraph = RecipeGraph.FromLibrary(l, new Item[] { item1 }, new ItemAmount[] { new ItemAmount(item2, 0.01) }, (a) => 1);
            var denseGraph  = TrivialSolutionFactory.CreateFactory(coarseGraph);

            var parameters = SolutionParameters.FromFactory(12, 12, denseGraph);

            Assert.AreEqual(parameters, parameters.Modify(0));
        }
示例#2
0
        private void UpdateResultView()
        {
            solveButton.Enabled = false;

            var inputs  = ParseDataView(ingredientsView);
            var outputs = ParseDataView(outputView);

            if (inputs == null || outputs == null)
            {
                return;
            }

            var costs = new Dictionary <Item, double>();

            foreach (var item in inputs)
            {
                costs.Add(item.Item1, item.Item2);
            }

            var outputAmounts = outputs.Select((t) => new ItemAmount(t.Item1, t.Item2));

            try
            {
                var graph = RecipeGraph.FromLibrary(_library, inputs.Select((t) => t.Item1), outputAmounts, (i) => costs[i]);

                if (expandCheckbox.CheckState == CheckState.Checked)
                {
                    graph = TrivialSolutionFactory.CreateFactory(graph);
                }

                resultView.Text = string.Join("\r\n", graph.Children.AsDot());
                _recipe         = graph;

                solveButton.Enabled = true;
            }
            catch (Exception e)
            {
                resultView.Text = e.Message;
            }
        }