private void InitSimulation() { v = new Visualization(dimX, canvas, polytope); v.DrawPoints = drawPts; switch (polytope) { case Polytope.Simplex: d0 = Simplex.GenerateDistanceMatrix(dimX); minimalization = new GradientDescent(d0, alpha, Simplex.GetVerticesCount(dimX)); //minimalization = new SimulatedAnnealing(1000, Simplex.GetVerticesCount(dimX), d0, dimY); break; case Polytope.Hypercube: d0 = Hypercube.GenerateDistanceMatrix(dimX); minimalization = new GradientDescent(d0, alpha, Hypercube.GetVerticesCount(dimX)); //minimalization = new SimulatedAnnealing(1000, Hypercube.GetVerticesCount(dimX), d0, dimY); break; default: break; } mds = new MDS(MDS.EuclideanDistance, MDS.KruskalStress, minimalization); s = mds.InitPos(); stressDisplay.Text = s.GetValue().ToString(); DrawSolution(s, zoom); iterationDisplay.Text = "0"; }
/// <summary> /// Loads MDS data from disk /// </summary> /// <returns>ReturnObject: Status bearing object</returns> /// <remarks> /// <para>Loads the MDS database from disk. If there is no file, we're screwed.</para> /// <para>Once MDS has been loaded, it's immediately transferred to the SDS, and /// the loading object is nulled.</para> /// <para>Raises the LoadMDSDataEevent(RO) on completion.</para> /// </remarks> ReturnObject LoadMDSData() { ReturnObject ro; if (File.Exists(MDSFilePath + MDSFileName)) { try { string stringMDS = File.ReadAllText(MDSFilePath + MDSFileName); MDS mds = JsonConvert.DeserializeObject <MDS>(stringMDS); gds.SDS.TransferFromMDS(mds); mds = null; ro = new ReturnObject(Enums.Return_Status.OK, "MDS loaded and transferred to SDS.", "MDS loaded and transferred to SDS.", null); } catch (Exception ex) { ro = new ReturnObject(Enums.Return_Status.Error, "Error loading MDS.", "Error loading MDS: " + ex.Message, null); } } else { //Uh...we don't have the file on disk... ro = new ReturnObject(Enums.Return_Status.Error, "Master data file was not found. Please reinstall.", "MDS file wasn't found at path " + MDSFilePath + MDSFileName, null); } OnLoadMDSDataEvent(ro); return(ro); }
private void ResetSimulation(object sender, RoutedEventArgs e) { // Stop simulation simulationInProgress = false; timer.Stop(); startButton.Content = "Start"; // Clear canvas if (v != null) { v.Clear(); } mds = null; s = null; v = null; minimalization = null; // Reset simulation InitSimulation(); // Unblock Controls ToggleControlsClear(false); ToggleControlsSimulation(false); }
// [FunctionName("ProcessEvents")] public Task <MDS> ProcessEvents(ItemEvent itemEvent) { StoreItems currentStoreItem; MDS currentMDS = new MDS(); if (storeItems == null) { storeItems = new Dictionary <string, StoreItems>(); } if (itemEvent != null) { string key = $"{itemEvent.divisionId}:{itemEvent.storeId}"; if (!storeItems.ContainsKey(key)) { currentStoreItem = new StoreItems(); currentStoreItem.storeId = itemEvent.storeId; currentStoreItem.divisionId = itemEvent.divisionId; currentStoreItem.items = new Dictionary <string, MDS>(); storeItems[key] = currentStoreItem; } currentStoreItem = storeItems[key]; if (!currentStoreItem.items.ContainsKey(itemEvent.upc)) { currentMDS = new MDS(); currentMDS.id = $"{itemEvent.divisionId}:{itemEvent.storeId}:{itemEvent.upc}"; currentMDS.storeId = itemEvent.storeId; currentMDS.divisionId = itemEvent.divisionId; currentMDS.upc = itemEvent.upc; currentMDS.inventoryCount = 0; currentMDS.description = itemEvent.description; currentMDS.productName = itemEvent.productName; currentMDS.lastUpdateTimestamp = itemEvent.lastUpdateTimestamp; currentMDS.lastShipmentTimestamp = itemEvent.lastShipmentTimestamp; currentStoreItem.items[itemEvent.upc] = currentMDS; } currentMDS = currentStoreItem.items[itemEvent.upc]; if (itemEvent.type == "onHandUpdate") { currentMDS.inventoryCount = itemEvent.countAdjustment; currentMDS.description = itemEvent.description; currentMDS.productName = itemEvent.productName; currentMDS.lastUpdateTimestamp = itemEvent.lastUpdateTimestamp; currentMDS.lastShipmentTimestamp = itemEvent.lastShipmentTimestamp; } else if (itemEvent.type == "shipmentUpdate") { currentMDS.inventoryCount += itemEvent.countAdjustment; currentMDS.description = itemEvent.description; currentMDS.productName = itemEvent.productName; currentMDS.lastUpdateTimestamp = itemEvent.lastUpdateTimestamp; currentMDS.lastShipmentTimestamp = itemEvent.lastShipmentTimestamp; } } //return currentMDS; return(Task.FromResult(currentMDS)); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); foreach (var MDS in MouseDownSubscribers) { MDS.OnMouseDown(e); } }
public GameState CurrentGameState = new GameState(); //Generated on new, loaded from save /*######################################################################################*/ /// <summary> /// After the MDS is loaded, and before a new game is created or /// an existing game is loaded, transfer the MDS data to the SDS /// object, and then trash the MDS object at the instantiation /// source (we don't need to keep it around) /// </summary> /// <param name="Source"></param> public void TransferFromMDS(MDS Source) { this.Sectors = Source.Sectors; this.Stations = Source.Stations; this.Shops = Source.Shops; this.Inventories = Source.Inventories; this.Items = Source.Items; this.MetaData = Source.MetaData; this.Jumpgates = Source.Jumpgates; this.MetaDataToEntity = Source.MetaDataToEntity; }
public static async Task RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context) { //var eventItem = await context.WaitForExternalEvent<ItemEvent>("StoreItemEvent"); //string data = context.GetInput<string>(); var eventItem = context.GetInput <ItemEvent>(); //Dictionary <string,StoreItems> storeItems = new Dictionary<string, StoreItems>(); var entityId = new EntityId("StoreItemEntity", $"{eventItem.divisionId}:{eventItem.storeId}"); var proxy = context.CreateEntityProxy <IStoreItemEntity>(entityId); MDS mdsItem = await proxy.ProcessEvents(eventItem); await context.CallActivityAsync("DBWriter", mdsItem); }
public static async Task DBWriter([ActivityTrigger] IDurableActivityContext dbcontext) { MDS mdsItem = dbcontext.GetInput <MDS>(); using (CosmosClient client = new CosmosClient(Environment.GetEnvironmentVariable("cosmoskimopenhack001_DOCUMENTDB", EnvironmentVariableTarget.Process))) { database = await client.CreateDatabaseIfNotExistsAsync("inventory"); // Create with a throughput of 1000 RU/s destinationContainer = database.GetContainer("mds"); ItemResponse <MDS> response = await destinationContainer.UpsertItemAsync( partitionKey : new PartitionKey(mdsItem.id), item : mdsItem); } //return "done"; }
public testLoadData(MDS.MainANN mainANN) { Hashtable data = mainANN.InputData; //List<double[]> oneSet; StreamWriter writer; writer = File.CreateText("test.data"); foreach (List<double[]> oneSet in data.Values) { foreach(double[] row in oneSet) { for (int i = 0; i < row.Length; i++) { writer.Write(row[i].ToString()); writer.Write(" "); } writer.Write("\r\n"); } } writer.Close(); }