public override int Mutate(NodeModel node) { NodeModel lastNode = DynamoModel.Nodes.ToList().Last(); if (lastNode.OutPorts.Count > 0) { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.MakeConnectionCommand connectCmd1 = new DynamoViewModel.MakeConnectionCommand(lastNode.GUID, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connectCmd2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, 0, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.ExecuteCommand(connectCmd1); DynamoViewModel.ExecuteCommand(connectCmd2); })); } else { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.MakeConnectionCommand connectCmd1 = new DynamoViewModel.MakeConnectionCommand(node.GUID, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connectCmd2 = new DynamoViewModel.MakeConnectionCommand(lastNode.GUID, 0, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.ExecuteCommand(connectCmd1); DynamoViewModel.ExecuteCommand(connectCmd2); })); } return 5; }
public override int Mutate(NodeModel node) { Random rand = new Random(1); int countOfInPorts = 0; var nodeConnectors = node.AllConnectors.ToList(); foreach (ConnectorModel connector in nodeConnectors) { if (connector.Start.Owner.GUID != node.GUID) { Guid guidNumber = Guid.NewGuid(); double coordinatesX = node.X * rand.NextDouble(); double coordinatesYNumber1 = node.Y * rand.NextDouble(); countOfInPorts++; DynamoViewModel.UIDispatcher.Invoke(new Action(() => { //make node DynamoViewModel.CreateNodeCommand createNodeNumber1 = new DynamoViewModel.CreateNodeCommand(guidNumber, "Number", coordinatesX, coordinatesYNumber1, false, true); //create node DynamoViewModel.ExecuteCommand(createNodeNumber1); int outPortIndex = connector.Start.Index; int inPortIndex = connector.End.Index; //make connection DynamoViewModel.MakeConnectionCommand connToStart1 = new DynamoViewModel.MakeConnectionCommand(guidNumber, outPortIndex, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToStart2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, inPortIndex, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); //create connections DynamoViewModel.ExecuteCommand(connToStart1); DynamoViewModel.ExecuteCommand(connToStart2); })); } } return countOfInPorts * 2; }
public override int Mutate(NodeModel node) { Random rand = new Random(1); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { Guid guidNumber = Guid.NewGuid(); double coordinatesX = node.X * rand.NextDouble(); double coordinatesY = node.Y * rand.NextDouble(); DynamoViewModel.CreateNodeCommand createNodeNumber1 = new DynamoViewModel.CreateNodeCommand(guidNumber, "Number", coordinatesX, coordinatesY, false, true); DynamoViewModel.ExecuteCommand(createNodeNumber1); DynamoViewModel.MakeConnectionCommand connToStart1 = new DynamoViewModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToStart2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, 0, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.MakeConnectionCommand connToAmount1 = new DynamoViewModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToAmount2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, 1, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.MakeConnectionCommand connToStep1 = new DynamoViewModel.MakeConnectionCommand(guidNumber, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToStep2 = new DynamoViewModel.MakeConnectionCommand(node.GUID, 2, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.ExecuteCommand(connToStart1); //"Number" with "Number Sequence" on Start DynamoViewModel.ExecuteCommand(connToStart2); //"Number" with "Number Sequence" on Start DynamoViewModel.ExecuteCommand(connToAmount1); //"Number" with "Number Sequence" on Amount DynamoViewModel.ExecuteCommand(connToAmount2); //"Number" with "Number Sequence" on Amount DynamoViewModel.ExecuteCommand(connToStep1); //"Number" with "Number Sequence" on Step DynamoViewModel.ExecuteCommand(connToStep2); //"Number" with "Number Sequence" on Step })); return 4; }
public override int Mutate(NodeModel node) { int workspaceIndex = DynamoViewModel.CurrentWorkspaceIndex; Random rand = new Random(1); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.SwitchTabCommand switchCmd = new DynamoViewModel.SwitchTabCommand(workspaceIndex); DynamoViewModel.ExecuteCommand(switchCmd); Thread.Sleep(100); })); DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.SwitchTabCommand switchCmd = new DynamoViewModel.SwitchTabCommand(workspaceIndex); DynamoViewModel.ExecuteCommand(switchCmd); Thread.Sleep(100); })); var workspaces = DynamoModel.Workspaces; var outputsInCustomNode = workspaces.FirstOrDefault((t) => { return (t.Name == ((Function)node).Definition.WorkspaceModel.Name); }).Nodes.Where(t => t.GetType() == typeof(Output)).ToList(); Guid numberGuid = Guid.NewGuid(); double coordinatesX = rand.NextDouble() * node.X; double coordinatesY = rand.NextDouble() * node.Y; DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.CreateNodeCommand createCommand = new DynamoViewModel.CreateNodeCommand(numberGuid, "Number", coordinatesX, coordinatesY, false, false); DynamoViewModel.ExecuteCommand(createCommand); })); foreach (NodeModel output in outputsInCustomNode) { DynamoViewModel.UIDispatcher.Invoke(new Action(() => { DynamoViewModel.MakeConnectionCommand connToAnother1 = new DynamoViewModel.MakeConnectionCommand(numberGuid, 0, PortType.OUTPUT, DynamoViewModel.MakeConnectionCommand.Mode.Begin); DynamoViewModel.MakeConnectionCommand connToAnother2 = new DynamoViewModel.MakeConnectionCommand(output.GUID, 0, PortType.INPUT, DynamoViewModel.MakeConnectionCommand.Mode.End); DynamoViewModel.ExecuteCommand(connToAnother1); DynamoViewModel.ExecuteCommand(connToAnother2); })); } int numberOfUndosNeeded = outputsInCustomNode.Count * 2 + 1; return numberOfUndosNeeded; }