private IEnumerable <Shelf> GetShelfData(RlmLearnedSessionDetails data) { var shelves = new List <Shelf>(); IDictionary <string, RlmIODetails> inputDict = data.Inputs.Where(a => a.CycleScore == 1).ToDictionary(a => a.Value, a => a); IDictionary <long, RlmIODetails> outputDict = data.Outputs.Where(a => a.CycleScore == 1).ToDictionary(a => a.CaseId, a => a); int numSlots = simSettings.NumShelves * simSettings.NumSlots; var shelf = new Shelf(); for (int i = 1; i <= numSlots; i++) { var input = inputDict[i.ToString()]; var output = outputDict[input.CaseId]; Item itemReference = itemsCache[Convert.ToInt32(output.Value)]; shelf.Add(itemReference, PlanogramOptimizer.GetCalculatedWeightedMetrics(itemReference, simSettings)); if (i % simSettings.NumSlots == 0) { shelves.Add(shelf); shelf = new Shelf(); } } return(shelves); }
protected void btnSubmit_Click(Object Sender, EventArgs e) { int intRoom = GetID(txtDepotRoom.Text, "cv_depot_rooms"); if (intRoom == 0) { oDepotRoom.Add(txtDepotRoom.Text, 1); intRoom = GetID(txtDepotRoom.Text, "cv_depot_rooms"); } int intShelf = GetID(txtShelf.Text, "cv_shelfs"); if (intShelf == 0) { oShelf.Add(txtShelf.Text, 1); intShelf = GetID(txtShelf.Text, "cv_shelfs"); } int intModel = Int32.Parse(ddlModel.SelectedItem.Value); DataSet ds = oAsset.Get(txtSerial.Text, intModel); if (ds.Tables[0].Rows.Count > 0) { Response.Redirect(oPage.GetFullLink(intPage) + "?pid=" + Request.QueryString["pid"] + "&tid=" + Request.QueryString["tid"] + "&mid=" + ddlModel.SelectedItem.Value + "&duplicate=true"); } else { int intAsset = oAsset.Add("", intModel, txtSerial.Text, txtAsset.Text, (int)AssetStatus.Arrived, intProfile, DateTime.Now, 0, 1); oAsset.AddNetwork(intAsset, "", (int)AssetStatus.Available, intProfile, DateTime.Now, Int32.Parse(ddlDepot.SelectedItem.Value), intRoom, intShelf, Int32.Parse(txtPorts.Text), 0, 0, 0, 0, 0, ""); Response.Redirect(oPage.GetFullLink(intPage) + "?pid=" + Request.QueryString["pid"] + "&tid=" + Request.QueryString["tid"] + "&mid=" + ddlModel.SelectedItem.Value + "&save=true"); } }
public static Shelf operator +(Shelf a, string b) { Shelf c = a.Clone(); c.Add(b); return(c); }
public static Shelf operator +(Shelf a, string[] b) { Shelf c = a.Clone(); foreach (string str in b) { c.Add(str); } return(c); }
public Shelf Clone() { Shelf d = new Shelf(); d.Capacity = Count; foreach (string str in this) { d.Add(str); } return(d); }
public PlanogramOptResults ScorePilot() { PlanogramOptResults retVal = new PlanogramOptResults(); var shelves = new List <Shelf>(); double totalMetricScore = 0; int slotNumber = 0; Dictionary <int, int> itemDict = new Dictionary <int, int>(); bool hasExceedMax = false; for (int i = 0; i < simSettings.NumShelves; i++) { Shelf shelfInstance = new Shelf(); for (int p = 0; p < simSettings.NumSlots; p++) { var inputs = new BasicMLData(1); inputs[0] = slotNormalizer.Normalize(slotNumber); IMLData output = network.Compute(inputs); int index = Convert.ToInt32(itemNormalizer.DeNormalize(output[0])); Item itemReference = items[index]; if (!hasExceedMax) { hasExceedMax = !(CheckDuplicateItem(itemDict, index)); } // with the item reference we will also have the Attributes which we need to calculate for the metrics double itemMetricScore = PlanogramOptimizer.GetCalculatedWeightedMetrics(itemReference, simSettings); // we add the item's metric score to totalMetricScore(which is our Session score in this case) // notice that we multplied it with the numFacings since that is how many will also show up on the planogram totalMetricScore += itemMetricScore; shelfInstance.Add(itemReference, itemMetricScore); slotNumber++; } shelves.Add(shelfInstance); } retVal.Shelves = shelves; retVal.Score = (hasExceedMax) ? 0 : totalMetricScore; retVal.TimeElapsed = DateTime.Now - simSettings.StartedOn; return(retVal); }
protected void btnSubmit_Click(Object Sender, EventArgs e) { int intAsset = Int32.Parse(Request.QueryString["id"]); oAsset.Update(intAsset, txtAsset.Text); IPAddresses oIPAddresses = new IPAddresses(intProfile, dsnIP, dsn); int intIP = oIPAddresses.Add(0, Int32.Parse(txtIP1.Text), Int32.Parse(txtIP2.Text), Int32.Parse(txtIP3.Text), Int32.Parse(txtIP4.Text), intProfile); int intDepotRoom = GetID(txtDepotRoom.Text, "cv_depot_rooms"); if (intDepotRoom == 0) { oDepotRoom.Add(txtDepotRoom.Text, 1); intDepotRoom = GetID(txtDepotRoom.Text, "cv_depot_rooms"); } int intShelf = GetID(txtShelf.Text, "cv_shelfs"); if (intShelf == 0) { oShelf.Add(txtShelf.Text, 1); intShelf = GetID(txtShelf.Text, "cv_shelfs"); } int intRoom = GetID(txtRoom.Text, "cv_rooms"); if (intRoom == 0) { oRooms.Add(txtRoom.Text, 1); intRoom = GetID(txtRoom.Text, "cv_rooms"); } int intRack = GetID(txtRack.Text, "cv_racks"); if (intRack == 0) { oRacks.Add(txtRack.Text, 1); intRack = GetID(txtRack.Text, "cv_racks"); } oAsset.UpdateNetwork(intAsset, txtName.Text, (int)AssetStatus.InUse, intProfile, DateTime.Parse(txtDate.Text), Int32.Parse(ddlDepot.SelectedItem.Value), intDepotRoom, intShelf, Int32.Parse(txtPorts.Text), Int32.Parse(ddlClass.SelectedItem.Value), Int32.Parse(Request.Form[hdnEnvironment.UniqueID]), Int32.Parse(Request.Form[hdnLocation.UniqueID]), intRoom, intRack, txtRackPosition.Text); oAsset.DeleteIP(intAsset); oAsset.AddIP(intAsset, intIP); if (Request.QueryString["sid"] != null) { Response.Redirect(oPage.GetFullLink(intPage) + "?sid=" + Request.QueryString["sid"] + "&id=" + intAsset.ToString() + "&commed=true"); } else { Response.Redirect(oPage.GetFullLink(intPage) + "?pid=" + Request.QueryString["pid"] + "&save=true"); } }
protected int GetShelf(string _name) { if (_name.Trim() == "") { return(0); } DataSet ds = SqlHelper.ExecuteDataset(dsn, CommandType.Text, "SELECT * FROM cv_shelfs WHERE name = '" + _name + "' AND enabled = 1 AND deleted = 0"); if (ds.Tables[0].Rows.Count == 0) { Shelf oShelf = new Shelf(intProfile, dsn); oShelf.Add(_name, 1); sb.Append("<tr><td>-</td><td>Add Shelf "); sb.Append(_name); sb.Append("</td></tr>"); return(GetShelf(_name)); } else { return(Int32.Parse(ds.Tables[0].Rows[0]["id"].ToString())); } }
protected void btnAdd_Click(Object Sender, EventArgs e) { if (Request.Form[hdnId.UniqueID] == "0") { oShelf.Add(txtName.Text, (chkEnabled.Checked ? 1 : 0)); } else { oShelf.Update(Int32.Parse(Request.Form[hdnId.UniqueID]), txtName.Text, (chkEnabled.Checked ? 1 : 0)); } if (Request.Form[hdnOrder.UniqueID] != "") { string strOrder = Request.Form[hdnOrder.UniqueID]; int intCount = 0; while (strOrder != "") { intCount++; int intId = Int32.Parse(strOrder.Substring(0, strOrder.IndexOf("&"))); strOrder = strOrder.Substring(strOrder.IndexOf("&") + 1); oShelf.UpdateOrder(intId, intCount); } } Response.Redirect(Request.Path); }
/// <summary> /// Does training or prediction for a set number of sessions /// </summary> /// <param name="sessions">Number of session to train/predict for</param> /// <param name="learn">Lets the RLM know if we are training or predicting</param> /// <returns>The final output for the training or prediction</returns> private PlanogramOptResults Optimize(int sessions, bool learn = true, bool enablePlanogramDisplay = false, CancellationToken?cancelToken = null) { var output = new PlanogramOptResultsSettings(); // holds the unique SKUs that are already in the planogram. Ensures there are no duplicate SKUs var hashedSku = new HashSet <int>(); var itemDict = new Dictionary <int, int>(); var shelves = new List <Shelf>(); double totalMetricScore = 0; for (int i = 0; i < sessions; i++) { // reset for next session shelves.Clear(); hashedSku.Clear(); itemDict.Clear(); ResetCurrentItemIndexes(); totalMetricScore = 0; totalSessions++; DateTime startSession = DateTime.Now; // starts the session. we need to save the session ID as we will pass it to the cycle.Run later on long sessionId = network.SessionStart(); int numSlotFlattened = 0; // iterates for how many number of shelves our planogram has for (int shelf = 1; shelf <= simSettings.NumShelves; shelf++) { // this shelf instance will hold the items the RLM will output var shelfInstance = new Shelf() { Number = shelf }; int itemIndex; int numFacings; // iterates for how many number of slots on each shelf // notice that the slot is incremented depending on how many number of facings was outputed by the RLM for (int slot = 1; slot <= simSettings.NumSlots; slot += numFacings) { itemIndex = -1; numFacings = -1; bool isValid = false; numSlotFlattened++; do { // create the inputs with their corresponding values var inputs = new List <RlmIOWithValue>(); //inputs.Add(new RlmIOWithValue(network.Inputs.First(a => a.Name == "Shelf"), shelf.ToString())); //inputs.Add(new RlmIOWithValue(network.Inputs.First(a => a.Name == "Slot"), slot.ToString())); inputs.Add(new RlmIOWithValue(network.Inputs.First(a => a.Name == "Slot"), numSlotFlattened.ToString())); var rlmItemOutput = network.Outputs.FirstOrDefault(); var rlmIdeas = new List <RlmIdea>() { new RlmOutputLimiter(rlmItemOutput.ID, currentItemIndexes.Count - 1, GetEquivalentIndex) }; // runs a cycle with the sessionId passed in var cycle = new RlmCycle(); var rlmOutput = cycle.RunCycle(network, sessionId, inputs, learn, ideas: rlmIdeas); // get the outputs // the RLM outputs the item index so we will get the actual reference to the Item later on and // the second output is the number of facings that will show up on the plangram itemIndex = Convert.ToInt32(rlmOutput.CycleOutput.Outputs.First(a => a.Name == "Item").Value); numFacings = 1;//Convert.ToInt32(rlmOutput.CycleOutput.Outputs.First(a => a.Name == "NumFacings").Value); // we calculate how many remaining slots are there left to check for validity // because there might not be enough slots for what the number of facings was outputed by the RLM int remainingSlots = simSettings.NumSlots - shelfInstance.Items.Count(); bool isWithinLimit = CheckDuplicateItem(itemDict, itemIndex, numFacings); // here we check if the item is not a duplicate and that we have enough slots to fit the number of facings //if (hashedSku.Add(itemIndex) && remainingSlots >= numFacings) if (isWithinLimit && remainingSlots >= numFacings) { isValid = true; Item itemReference = items[itemIndex]; // we get the item reference using the index outputed by the RLM // with the item reference we will also have the Attributes which we need to calculate for the metrics double itemMetricScore = PlanogramOptimizer.GetCalculatedWeightedMetrics(itemReference, simSettings); // we add the item's metric score to totalMetricScore(which is our Session score in this case) // notice that we multplied it with the numFacings since that is how many will also show up on the planogram totalMetricScore += (itemMetricScore * numFacings); // add the items to the shelf container depending on how many facings for (int n = 0; n < numFacings; n++) { shelfInstance.Add(itemReference, itemMetricScore); } // A non-duplicate is good. network.ScoreCycle(rlmOutput.CycleOutput.CycleID, 1); } else { // we give the cycle a zero (0) score as it was not able to satisfy our conditions (punish it) isValid = false; network.ScoreCycle(rlmOutput.CycleOutput.CycleID, -1); //System.Diagnostics.Debug.WriteLine("try again"); } } while (!isValid); // if invalid, we redo the whole thing until the RLM is able to output an item that is unique and fits the remaining slot in the planogram } shelves.Add(shelfInstance); } // ends the session with the summed metric score for all items in the planogram network.SessionEnd(totalMetricScore); System.Diagnostics.Debug.WriteLine($"Session #{i}, Score: {totalMetricScore}"); // set statistics and the optimized planogram shelves (and items inside them) output.Shelves = shelves; metricScoreHistory.Add(totalMetricScore); metricAvgLastTen.Enqueue(totalMetricScore); if (metricAvgLastTen.Count > 10) { metricAvgLastTen.Dequeue(); } output.Score = totalMetricScore; output.AvgScore = metricScoreHistory.Average(); output.AvgLastTen = metricAvgLastTen.Average(); output.MinScore = metricScoreHistory.Min(); output.MaxScore = metricScoreHistory.Max(); output.TimeElapsed = DateTime.Now - simSettings.StartedOn; output.CurrentSession = totalSessions; output.MaxItems = MAX_ITEMS; output.StartRandomness = network.StartRandomness; output.EndRandomness = network.EndRandomness; output.SessionsPerBatch = DEFAULT_SESSIONS_PER_BATCH; output.InputType = inputType.ToString(); output.CurrentRandomnessValue = network.RandomnessCurrentValue; if (logger != null) { SimulationData logdata = new SimulationData(); logdata.Session = output.CurrentSession; logdata.Score = output.Score; logdata.Elapse = DateTime.Now - startSession; logger.Add(logdata); } // update the numScoreHits if the sim type is Score if (simSettings.SimType == SimulationType.Score) { if (totalMetricScore >= simSettings.Score.Value) { numScoreHits++; output.NumScoreHits = numScoreHits; } else { numScoreHits = 0; } } //OnSessionDone?.Invoke(output); // updates the results to the UI //bool enableSimDisplay = (!learn) ? true : (learn && simSettings.EnableSimDisplay) ? true : false; if (enablePlanogramDisplay) { output.MetricMin = simSettings.ItemMetricMin; output.MetricMax = simSettings.ItemMetricMax; output.CalculateItemColorIntensity(); } UpdateUI?.Invoke(output, enablePlanogramDisplay); // checks if we have already by passed the time or score that was set // if we did, then we stop the training and end it abruptly if ((simSettings.SimType == SimulationType.Time && simSettings.EndsOn.Value <= DateTime.Now) || (simSettings.SimType == SimulationType.Score && numScoreHits >= SimulationSettings.NUM_SCORE_HITS)) { break; } if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested) { return(output); } } return(output); }