//Methods private void solveProblemAndDisplay(TransportProblem p) { //Result variable string sHTML = ""; #region Check Problem sHTML += "Balanced Problem: " + p.isBalanced + "</br>"; if (!p.isBalanced) { sHTML += "Transport problem is not balanced!" + "</br>"; sHTML += "Suppliers: " + p.Suppliers.Sum() + "</br>"; sHTML += "Demanders: " + p.Demanders.Sum() + "</br>"; } #endregion //Spacer sHTML += "</br>"; //If a proper problem, then solve if (p.isBalanced) { #region Method 1: NorthWest double[,] solutionNorthWest = p.solveNorthWest(); double costNorthWest = p.calculateCost(solutionNorthWest); //632 <-- correct sHTML += "<b>Solution: North West Method</b>" + "</br>"; sHTML += "Cost: " + costNorthWest + "</br>"; sHTML += p.solutionToHTML(solutionNorthWest); #endregion //Spacer sHTML += "</br>"; #region Method 2: Minimum Cost Element double[,] solutionMinimumCostElement = p.solveMinimumCostElement(); double costMinimumCostElement = p.calculateCost(solutionMinimumCostElement); sHTML += "<b>Solution: Minimum Cost Element Method</b>" + "</br>"; sHTML += "Cost: " + costMinimumCostElement + "</br>"; sHTML += p.solutionToHTML(solutionMinimumCostElement); #endregion //Spacer sHTML += "</br>"; #region Method 3: UV int cycles = 0; double[,] solutionUV = p.solveUV(out cycles); double costUV = p.calculateCost(solutionUV); sHTML += "<b>Solution: Least Potentials Optimization</b>" + "</br>"; sHTML += "Cost: " + costUV + "</br>"; sHTML += "Cycles: " + cycles + "</br>"; sHTML += p.solutionToHTML(solutionUV); #endregion } //Send to Browser wbResults.Url = new Uri("about: blank"); wbResults.DocumentText = "<html>" + p.styleHTML() + sHTML + "</html>"; wbResults.Visible = true; }
private void btnSample81_MinDel_Click(object sender, EventArgs e) { TransportProblem p = SampleProblems.p81_MinimumDelivery; gridCosts.Supply = p.Suppliers; gridCosts.Demand = p.Demanders; gridCosts.Grid = p.Costs; gridMinDelivery.Grid = p.MinimumDelivery; }
//Controls private void btnGo_Click(object sender, EventArgs e) { //Define the default problem TransportProblem p = new TransportProblem(4, 5); p.Suppliers = gridCosts.Supply; p.Demanders = gridCosts.Demand; p.Costs = gridCosts.Grid; p.MinimumDelivery = gridMinDelivery.Grid; //Solve the problem and display in the web browser if (p.isReady) { solveProblemAndDisplay(p); } }