public ActionResult <IEnumerable <PurchaseViewModel> > Cost([FromBody] string[] skus) { var purchases = CostCalculationService.CalculateCost(skus); var purchaseViewModel = _mapper.Map <IEnumerable <PurchaseViewModel> >(purchases); return(new ActionResult <IEnumerable <PurchaseViewModel> >(purchaseViewModel)); }
private void SimulationStepSwitch() { Dictionary <MyRoom, double> RoomCosts = new Dictionary <MyRoom, double>(); double actualCost = CostCalculationService.CalculateCost(model).First(); double mincost = actualCost; int rooms = model.modelRooms.Count; MyRoom switchThisMyRoomFrom = null; MyRoom switchThisMyRoomTo = null; Parallel.For(0, rooms, index => { Parallel.For(index + 1, rooms, secondindex => { MyRoom r1 = model.modelRooms.ElementAt(index); MyRoom r2 = model.modelRooms.ElementAt(secondindex); MyRoom r1target = null; MyRoom r2target = null; Model tempModel = model.DeepCopy(r1, r2, out r1target, out r2target); tempModel.SwitchRooms(ref r1target, ref r2target); double cost = CostCalculationService.CalculateCost(tempModel).First(); lock (locker) { RoomCosts.Add(r1, cost); if (mincost >= cost) { mincost = cost; //this might need to be switched later switchThisMyRoomFrom = r1; switchThisMyRoomTo = r2; } } }); }); if (mincost >= actualCost) { actualSimulationThreshold++; } if (switchThisMyRoomFrom != null && switchThisMyRoomTo != null) { model.SwitchRooms(ref switchThisMyRoomFrom, ref switchThisMyRoomTo); } else { MessageBox.Show("no room to switch"); } double[] costArray = CostCalculationService.CalculateCost(model); SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3])); actualSimulationIndex++; }
private void SimulationStepMove() { Dictionary <string, double> Costs = new Dictionary <string, double>(); MyLine minline = null; int currentMoveDistance = moveDistance; double actualCost = CostCalculationService.CalculateCost(model).First(); double mincost = actualCost; Parallel.For(0, model.modelLines.Count, index => { MyLine myLine = model.modelLines.ElementAt(index); MyLine newMyLine = null; Model tempModel = model.DeepCopy(myLine, out newMyLine); tempModel.MoveLine(moveDistance, newMyLine); double cost = CostCalculationService.CalculateCost(tempModel).First(); lock (locker) { Costs.Add("+" + myLine.ToString(), cost); if (mincost > cost) { mincost = cost; minline = myLine; currentMoveDistance = moveDistance; } } }); Parallel.For(0, model.modelLines.Count, index => { MyLine myLine = model.modelLines.ElementAt(index); MyLine newMyLine = null; Model tempModel = model.DeepCopy(myLine, out newMyLine); tempModel.MoveLine(-moveDistance, newMyLine); double cost = CostCalculationService.CalculateCost(tempModel).First(); lock (locker) { Costs.Add("-" + myLine.ToString(), cost); if (mincost > cost) { mincost = cost; minline = myLine; currentMoveDistance = -moveDistance; } } }); if (mincost >= actualCost) { actualSimulationThreshold++; } if (minline != null) { model.MoveLine(currentMoveDistance, minline); } else { MessageBox.Show("no line to move"); } LineAndCostActualStep.Clear(); foreach (var item in Costs) { LineAndCostActualStep.Add(new LineAndCost(item.Key, item.Value, actualSimulationIndex)); } //System.Windows.Forms.MessageBox.Show(mincost.ToString()); //SimulationCosts.Add(new Costs(actualSimulationIndex, mincost)); double[] costArray = CostCalculationService.CalculateCost(model); SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3])); actualSimulationIndex++; }