Exemple #1
0
    /// <summary>
    /// Creates a Logic Graph from the data in this Class
    /// </summary>
    public LogicChip getLogicGraph()
    {
        LogicChip result = new LogicChip(this.Width, this.Height, this.Name);

        foreach (GraphComponentData gcd in this.Components)
        {
            Type           type           = Type.GetType(gcd.Type);
            LightComponent lightComponent = null;

            if (type.IsSubclassOf(typeof(LightComponent)))
            {
                if (!type.IsSubclassOf(typeof(LinkComponent)))
                {
                    lightComponent = (LightComponent)Activator.CreateInstance(
                        type, new object[] {
                        new Vector2Int(gcd.Position[0], gcd.Position[1]),
                        gcd.Rotaiton,
                        gcd.Flipped
                    });
                }
                else
                {
                    if (type == typeof(GraphOutput))
                    {
                        lightComponent = new GraphOutput(new Vector2Int(gcd.Position[0], gcd.Position[1]),
                                                         gcd.Rotaiton,
                                                         gcd.Flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND));
                    }
                    else if (type == typeof(GraphInput))
                    {
                        lightComponent = new GraphInput(new Vector2Int(gcd.Position[0], gcd.Position[1]),
                                                        gcd.Rotaiton,
                                                        gcd.Flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE));
                    }
                    else
                    {
                        throw new Exception(type + " is not supported when loading data");
                    }
                }

                if (type.IsSubclassOf(typeof(LogicComponent)))
                {
                    LogicComponent logic = (LogicComponent)lightComponent;
                    logic.setState();
                }
            }
            else
            {
                throw new Exception("Type " + type + " is not accepted from LogicGraphData");
            }

            if (lightComponent != null)
            {
                lightComponent.setValues(gcd.Values);
                result.LightGraph.addComponent(lightComponent);
            }
        }

        return(result);
    }
        private static void SetInputOutputPosition(FlowGraph graph, GraphInput input, GraphOutput output)
        {
            var posXIn  = 0f;
            var posYIn  = 0f;
            var posXOut = 0f;
            var posYOut = 0f;

            for (int i = 0; i < graph.units.Count; i++)
            {
                if (posXIn >= graph.units[i].position.x)
                {
                    posXIn = graph.units[i].position.x;
                    posYIn = graph.units[i].position.y;
                }

                if (graph.units[i].position.x <= posXOut)
                {
                    posXOut = graph.units[i].position.x;
                    posYOut = graph.units[i].position.y;
                }
            }

            input.position  = new Vector2(posXIn - 240, posYIn);
            output.position = new Vector2(posXOut + 240, posYOut);
        }
 private static void CopyInvalidConnectionData(FlowGraph superUnitGraph, GraphInput graphInput, GraphOutput graphOutput, List <ConnectionData> connectionData)
 {
     for (int i = 0; i < connectionData.Count; i++)
     {
         superUnitGraph.invalidConnections.Add(new InvalidConnection(superUnitGraph.units[connectionData[i].sourceUnitIndex].invalidOutputs.ToList()[connectionData[i].sourceOutputIndex] as IUnitOutputPort,
                                                                     superUnitGraph.units[connectionData[i].destinationUnitIndex].invalidInputs.ToList()[connectionData[i].destinationInputIndex] as IUnitInputPort));
     }
 }
Exemple #4
0
    public bool removeComponent(LightComponent component)
    {
        //removes the component from the graph
        bool result = false;

        List <LightComponent> all = this.getAllGraphComponents();
        int counter = 0;

        while (counter < all.Count && !result)
        {
            if (all[counter].Equals(component))
            {
                if (component.GetType().IsSubclassOf(typeof(LogicComponent)))
                {
                    result = this.logicComponents.Remove((LogicComponent)component);
                }
                else if (component.GetType().IsSubclassOf(typeof(PassiveComponent)))
                {
                    result = this.passiveComponents.Remove((PassiveComponent)component);
                }
                else if (component.GetType().IsSubclassOf(typeof(LinkComponent)))
                {
                    //ExtensionConnection[]
                    if (component.GetType() == typeof(GraphInput))
                    {
                        GraphInput rec = (GraphInput)component;
                        result = this.logicGraph.removeReceiveBridge(rec.getExtensionConnection());
                        this.linkComponents.Remove(rec);
                    }
                    else if (component.GetType() == typeof(GraphOutput))
                    {
                        GraphOutput send = (GraphOutput)component;
                        result = this.logicGraph.removeSendBridge(send.getExtensionConnection());
                        this.linkComponents.Remove(send);
                    }
                    else
                    {
                        throw new System.Exception(component.GetType() + " can not be removed to the Logic Graph");
                    }
                }
                else
                {
                    throw new Exception("TypeNotFound: type " + component.GetType() + " is not a subclass on the looked at classes");
                }
            }
            counter++;
        }

        if (result == true)
        {
            //redundent statement but i like it

            this.LGUtilities.disconnectGraph();
            this.LGUtilities.connectGraph();
        }

        return(result);
    }
Exemple #5
0
        public void MininalDistanceTestVeryLarge()
        {
            Console.SetIn(new System.IO.StreamReader("D:\\Documentos\\Downloads\\input015.txt"));
            var gi     = GraphInput.FromReader(Console.In);
            var reader = new System.IO.StreamReader("D:\\Documentos\\Downloads\\output015.txt");
            int t      = 0;

            foreach (Graph <int> graph in gi.Graphs)
            {
                var result = graph.MinimalDistances(gi.StartNode[t]);
                t += 1;
                Assert.AreEqual(reader.ReadLine(), String.Join(" ", result.OrderBy(kvp => kvp.Key.Data).Select(kvp => double.IsPositiveInfinity(kvp.Value) ? -1 : kvp.Value)));
            }
        }
Exemple #6
0
        public void GraphInputTest()
        {
            var input  = @"2
4 2
1 2
1 3
1
3 1
2 3
2";
            var reader = new StringReader(input);
            var gi     = GraphInput.FromReader(reader);

            Assert.IsTrue(true);
        }
        private static void CopyValueConnectionData(FlowGraph superUnitGraph, GraphInput graphInput, GraphOutput graphOutput, List <ConnectionData> connectionData)
        {
            List <string> keys = new List <string>();

            for (int i = 0; i < connectionData.Count; i++)
            {
                var index = i;

                var _key = GetKeyName(connectionData[i], keys);

                if (!keys.Contains(_key))
                {
                    keys.Add(_key);
                }

                switch (connectionData[index].source)
                {
                case ConnectionDataSource.GraphInput:
                    var def       = connectionData[index].valueType.Default();
                    var isDefault = def != null;
                    superUnitGraph.valueInputDefinitions.Add(new ValueInputDefinition()
                    {
                        key  = _key,
                        type = connectionData[index].valueType
                    });
                    superUnitGraph.PortDefinitionsChanged();
                    graphInput.valueOutputs.Single((op) => { return(op.key == _key); }).ConnectToValid(superUnitGraph.units[connectionData[index].destinationUnitIndex].valueInputs.ToList()[connectionData[index].destinationInputIndex] as ValueInput);
                    connectionData[index].subgraph.valueInputs.Single((op) => { return(op.key == _key); }).ConnectToValid(connectionData[index].externalPort as ValueOutput);
                    break;

                case ConnectionDataSource.GraphOutput:
                    superUnitGraph.valueOutputDefinitions.Add(new ValueOutputDefinition()
                    {
                        key  = _key,
                        type = connectionData[index].valueType,
                    });
                    superUnitGraph.PortDefinitionsChanged();
                    graphOutput.valueInputs.Single((op) => { return(op.key == _key); }).ConnectToValid(superUnitGraph.units[connectionData[index].sourceUnitIndex].valueOutputs.ToList()[connectionData[index].sourceOutputIndex] as ValueOutput);
                    connectionData[index].subgraph.valueOutputs.Single((op) => { return(op.key == _key); }).ConnectToValid(connectionData[index].externalPort as ValueInput);
                    break;

                case ConnectionDataSource.Node:
                    superUnitGraph.valueConnections.Add(new ValueConnection(superUnitGraph.units[connectionData[index].sourceUnitIndex].valueOutputs.ToList()[connectionData[index].sourceOutputIndex] as ValueOutput,
                                                                            superUnitGraph.units[connectionData[index].destinationUnitIndex].valueInputs.ToList()[connectionData[index].destinationInputIndex] as ValueInput));
                    break;
                }
            }
        }
        private static void ConvertToEmbed()
        {
            var selection = GraphWindow.active?.reference?.graph?.Canvas().selection;

            if (selection != null && selection.Count > 0)
            {
                Undo.RegisterCompleteObjectUndo(GraphWindow.active?.reference.rootObject, "Add Sub Graph to Script Graph");

                var superUnit       = new NestedNode();
                var superUnitGraph  = new FlowGraph();
                var superUnitCanvas = superUnitGraph.Canvas <FlowCanvas>();
                var elements        = selection.ToList();

                superUnit.position = GetNestedNodePosition(elements);

                ((FlowGraph)GraphWindow.active.reference.graph).units.Add(superUnit);

                superUnit.nest.SwitchToEmbed(superUnitGraph);

                CopyElementsToGraph(superUnitCanvas);

                var graphInput  = new GraphInput();
                var graphOutput = new GraphOutput();

                var listWithoutInputOutput = ((FlowGraph)GraphWindow.active.reference.graph).units.ToList();

                superUnitGraph.units.Add(graphInput);
                superUnitGraph.units.Add(graphOutput);

                CopyControlConnectionData(superUnitGraph, graphInput, graphOutput, GetControlIndices(selection, superUnit));
                CopyValueConnectionData(superUnitGraph, graphInput, graphOutput, GetValueIndices(selection, superUnit));
                CopyInvalidConnectionData(superUnitGraph, graphInput, graphOutput, GetInvalidIndices(selection, superUnit));

                SetInputOutputPosition(superUnitGraph, graphInput, graphOutput);

                superUnitGraph.pan = superUnit.position;

                RemoveUnusedDefinitions(superUnitGraph);

                superUnitGraph.PortDefinitionsChanged();

                GraphWindow.active.reference.graph.Canvas <FlowCanvas>().DeleteSelection();
                GraphWindow.active.reference.graph.Canvas <FlowCanvas>().selection.Add(superUnit);
            }
        }
Exemple #9
0
        public void MininalDistanceTest()
        {
            var input   = @"2
7 7
1 2
1 4
2 5
2 3
4 5
3 5
6 7
1
7 7
1 2
1 4
2 5
2 3
4 5
3 5
6 7
6";
            var outputs = new List <string>(2)
            {
                "6 12 6 12 -1 -1", "-1 -1 -1 -1 -1 6"
            };
            var actualOutputs = new List <string>();
            var reader        = new StringReader(input);
            var gi            = GraphInput.FromReader(reader);
            int t             = 0;

            foreach (Graph <int> graph in gi.Graphs)
            {
                var result = graph.MinimalDistances(gi.StartNode[t]);
                t += 1;
                actualOutputs.Add(String.Join(" ", result.OrderBy(kvp => kvp.Key.Data).Select(kvp => double.IsPositiveInfinity(kvp.Value) ? -1 : kvp.Value)));
            }

            for (int i = 0; i < actualOutputs.Count; i++)
            {
                Assert.AreEqual(outputs[i], actualOutputs[i]);
            }
        }
Exemple #10
0
        public void GraphInputTest()
        {
            var input       = @"2
4 2
1 2
1 3
1
3 1
2 3
2";
            var outputNodes = new List <string>(2)
            {
                "1 2 3 4", "1 2 3"
            };
            var outputEdges = new List <string>(2)
            {
                "2 3|1|1|", "|3|2"
            };
            var reader            = new StringReader(input);
            var gi                = GraphInput.FromReader(reader);
            var actualOutputNodes = new List <string>(2);
            var actualOutputEdges = new List <string>(2);

            foreach (Graph <int> graph in gi.Graphs)
            {
                actualOutputNodes.Add(String.Join(" ", graph.Nodes.OrderBy(node => node.Data).Select(node => node.Data)));
                actualOutputEdges.Add(String.Join("|", graph.Nodes.OrderBy(node => node.Data).Select(node => String.Join(" ", node.Neighboors.Select(nnode => nnode.Node.Data)))));
            }

            for (int i = 0; i < actualOutputNodes.Count; i++)
            {
                Assert.AreEqual(outputNodes[i], actualOutputNodes[i]);
            }
            for (int i = 0; i < actualOutputEdges.Count; i++)
            {
                Assert.AreEqual(outputEdges[i], actualOutputEdges[i]);
            }
        }
        public async Task <IActionResult> Post([FromBody] GraphInput input)
        {
            try
            {
                var graphResponse = new GraphResponse
                {
                    DeviceID        = input.DeviceID,
                    DeviceName      = (await _context.Device_info.FindAsync(input.DeviceID)).Device_Name,
                    ParamID         = input.ParameterID,
                    ParamName       = (await _context.Parameter_Masters.FindAsync(input.ParameterID)).Param_Name,
                    ParameterValues = new List <ParamForGraph>()
                };

                switch (input.Type)
                {
                case "Daily":

                    graphResponse.ParameterValues = await _context.SensorData
                                                    .Where(w => w.Device_Id == input.DeviceID && w.Param_Id == input.ParameterID)
                                                    .Select(s => new ParamForGraph
                    {
                        date  = s.DataEntryTime,
                        value = s.Input_Value
                    }).ToListAsync();

                    return(Ok(graphResponse));

                default:
                    return(BadRequest("Please select type as : Daily / Weekly / Monthly"));
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError($"Problem in getting the data for graph : {ex.Message}");
                return(BadRequest("Data not present for the mentioned criteria"));
            }
        }
Exemple #12
0
 protected override async Task OnInitializedAsync()
 {
     GraphInput  = new GraphInput(0, 5, true);
     PathIsFound = false;
 }
 public bool Connectable(GraphOutput output, GraphInput input)
 {
     return(output != null && input != null && output.connectTypeId == input.connectTypeId &&
            output.body is GraphNode_Mission);
 }
 public void ExtractModules_GivenValidInput_ReturnsModuleList(string input, Graph expected)
 {
     var modules = new GraphInput(input).ExtractModules();
     Assert.AreEqual(expected.Modules.Count, modules.Length);
    
 }
Exemple #15
0
 public void GraphInputTestVeryLarge()
 {
     Console.SetIn(new System.IO.StreamReader("D:\\Documentos\\Downloads\\input015.txt"));
     var gi = GraphInput.FromReader(Console.In);
 }
 public ConceptSchemeGraphRequest()
 {
     GraphInput = new GraphInput();
 }
Exemple #17
0
    private LightComponent duplicateAt(Type type, Vector2Int position, int rotation, bool flipped)
    {
        //makes a duplicate of the component passed in

        LightComponent result = null;

        if (type == typeof(AndGate))
        {
            result = new AndGate(position, rotation, flipped);
        }
        else if (type == typeof(OrGate))
        {
            result = new OrGate(position, rotation, flipped);
        }
        else if (type == typeof(NotGate))
        {
            result = new NotGate(position, rotation, flipped);
        }
        else if (type == typeof(BufferGate))
        {
            result = new BufferGate(position, rotation, flipped);
        }
        else if (type == typeof(NandGate))
        {
            result = new NandGate(position, rotation, flipped);
        }
        else if (type == typeof(XorGate))
        {
            result = new XorGate(position, rotation, flipped);
        }
        else if (type == typeof(XnorGate))
        {
            result = new XnorGate(position, rotation, flipped);
        }
        else if (type == typeof(NorGate))
        {
            result = new NorGate(position, rotation, flipped);
        }
        else if (type == typeof(Splitter))
        {
            result = new Splitter(position, rotation, flipped);
        }
        else if (type == typeof(Reflector))
        {
            result = new Reflector(position, rotation, flipped);
        }
        else if (type == typeof(GraphOutput))
        {
            result = new GraphOutput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND));
        }
        else if (type == typeof(GraphInput))
        {
            result = new GraphInput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE));
        }
        else
        {
            throw new System.Exception(type + " was not found when selecting the from the logic graph editor");
        }

        return(result);
    }
 public bool Connectable(GraphOutput output, GraphInput input)
 {
     return(input.body is GraphNode_Mission);
 }