public override int Mutate() { List<NodeModel> nodes = DynamoModel.Nodes.Where(x => x.GetType() == typeof (CodeBlockNodeModel)).ToList(); //If there aren't any CBNs, we can't mutate anything if (nodes.Count == 0) return 0; NodeModel node = nodes[Rand.Next(nodes.Count)]; dynSettings.Controller.UIDispatcher.Invoke(new Action(() => { string code = ((CodeBlockNodeModel) node).Code; if (code.Length == 0) code = ""; string replacement; if (Rand.NextDouble() <= 0.5) { //Strategy 1: Replacement with simplest minimal replacement replacement = "1;"; } else { //Strategy 2: Noise injection replacement = code; while (Rand.NextDouble() > 0.5) { int locat = Rand.Next(code.Length); const string junk = "<>:L/;'\\/["; replacement = code.Substring(0, locat) + junk[Rand.Next(junk.Length)] + code.Substring(locat); } } DynamoViewModel.UpdateModelValueCommand cmd = new DynamoViewModel.UpdateModelValueCommand(node.GUID, "Code", replacement); DynamoViewModel.ExecuteCommand(cmd); })); //We've performed a single edit from the perspective of undo return 1; }
public Guid RunDSScriptInCBN(string dscode) { /// Method that takes the DesignScript language code and dumps into CBN. /// Then evaluate in Dynamo and return the guid of the CBN var guid = Guid.NewGuid(); var command1 = new DynamoViewModel.CreateNodeCommand(guid, "Code Block", 0, 0, false, false); ViewModel.ExecuteCommand(command1); var command2 = new DynamoViewModel.UpdateModelValueCommand(guid, "Code", dscode); ViewModel.ExecuteCommand(command2); Assert.DoesNotThrow(() => ViewModel.Model.RunExpression()); return guid; }
public override int Mutate(NodeModel node) { string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*(),./[];=-:<\\>?"; Random random = new Random(); string value = new string(Enumerable.Repeat(chars, 10).Select(s => s[random.Next(s.Length)]).ToArray()); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.UpdateModelValueCommand updateValue = new DynamoViewModel.UpdateModelValueCommand(node.GUID, "Value", value); DynamoViewModel.ExecuteCommand(updateValue); })); return 1; }
public override int Mutate(NodeModel node) { Random Rand = new Random(1); this.DynamoViewModel.UIDispatcher.Invoke(new Action(() => { string code = ((CodeBlockNodeModel)node).Code; if (code.Length == 0) code = ""; string replacement; if (Rand.NextDouble() <= 0.5) { //Strategy 1: Replacement with simplest minimal replacement replacement = "1;"; } else { //Strategy 2: Noise injection replacement = code; while (Rand.NextDouble() > 0.5) { int locat = Rand.Next(code.Length); const string junk = "<>:L/;'\\/[=+-"; replacement = code.Substring(0, locat) + junk[Rand.Next(junk.Length)] + code.Substring(locat); } } var cmd = new DynamoViewModel.UpdateModelValueCommand(node.GUID, "Code", replacement); this.DynamoViewModel.ExecuteCommand(cmd); })); //We've performed a single edit from the perspective of undo return 1; }
public override int Mutate(NodeModel node) { string assemblyPath = Assembly.GetExecutingAssembly().Location; string assemblyDir = Path.GetDirectoryName(assemblyPath); string pathToNodesDll = assemblyDir + "\\nodes\\DSCoreNodesUI.dll"; Assembly assembly = Assembly.LoadFile(pathToNodesDll); Type type = assembly.GetType("Dynamo.Nodes.IntegerSlider"); PropertyInfo propInfo = type.GetProperty("Min"); dynamic propertyMin = propInfo.GetValue(node, null); propInfo = type.GetProperty("Max"); dynamic propertyMax = propInfo.GetValue(node, null); int min = 0; int max = 0; int returnCode = 0; Random rand = new Random(); if (Int32.TryParse(propertyMin.ToString(), out min) && Int32.TryParse(propertyMax.ToString(), out max)) { string value = (rand.Next(min, max)).ToString(); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.UpdateModelValueCommand updateValue = new DynamoViewModel.UpdateModelValueCommand(node.GUID, "Value", value); DynamoViewModel.ExecuteCommand(updateValue); })); returnCode = 1; } return returnCode; }
public override int Mutate(NodeModel node) { Random rand = new Random(1); string value = rand.Next(100).ToString(); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.UpdateModelValueCommand updateValue = new DynamoViewModel.UpdateModelValueCommand(node.GUID, "Value", value); DynamoViewModel.ExecuteCommand(updateValue); })); return 1; }
public override int Mutate(NodeModel node) { string assemblyPass = Environment.CurrentDirectory + "\\nodes\\DSCoreNodesUI.dll"; Assembly assembly = Assembly.LoadFile(assemblyPass); Type type = assembly.GetType("Dynamo.Nodes.DoubleSlider"); PropertyInfo propInfo = type.GetProperty("Min"); dynamic propertyMin = propInfo.GetValue(node, null); propInfo = type.GetProperty("Max"); dynamic propertyMax = propInfo.GetValue(node, null); double min = 0; double max = 0; int returnCode = 0; Random rand = new Random(1); if (double.TryParse(propertyMin.ToString(), out min) && double.TryParse(propertyMax.ToString(), out max)) { string value = (min + (max - min) * rand.NextDouble()).ToString(); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.UpdateModelValueCommand updateValue = new DynamoViewModel.UpdateModelValueCommand(node.GUID, "Value", value); DynamoViewModel.ExecuteCommand(updateValue); })); returnCode = 1; } return returnCode; }
public override int Mutate(NodeModel node) { string assemblyPath = Assembly.GetExecutingAssembly().Location; DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.UpdateModelValueCommand updateValue = new DynamoViewModel.UpdateModelValueCommand(node.GUID, "Value", assemblyPath); DynamoViewModel.ExecuteCommand(updateValue); })); return 1; }