Package Hack.Utilities

Examples of Hack.Utilities.Graph


        isInputClocked = new boolean[inputPinsInfo.length];
        isOutputClocked = new boolean[outputPinsInfo.length];

        readParts(input);

        Graph graph = createConnectionsGraph();

        // runs the topological sort, starting from the "master parts" node,
        // which connects to all the parts. This will also check for circles.
        Object[] topologicalOrder = graph.topologicalSort(partsList);

        if (graph.hasCircle())
            throw new HDLException("This chip has a circle in its parts connections");

        // create the partsOrder array, by taking from the topologicalOrder
        // only the Integer objects, which represent the parts.
        partsOrder = new int[partsList.size()];
        int counter = 0;
        for (int i = 0; i < topologicalOrder.length; i++) {
            if (topologicalOrder[i] instanceof Integer)
                partsOrder[counter++] = ((Integer)topologicalOrder[i]).intValue();
        }

        // for each input pin, check if there is a path in the graph to an output pin
        // (actually to the "master output", which all outputs connect to).
        // If there is, the input is not clocked. Otherwise, it is.
        for (int i = 0; i < inputPinsInfo.length; i++)
            isInputClocked[i] = !graph.pathExists(inputPinsInfo[i], outputPinsInfo);

        // for each output pin, check if there is a path in the graph from any input pin
        // (actually from the "master input", which connects to all inputs) to this output pin.
        // If there is, the output is not clocked. Otherwise, it is.
        for (int i = 0; i < outputPinsInfo.length; i++)
            isOutputClocked[i] = !graph.pathExists(inputPinsInfo, outputPinsInfo[i]);
    }
View Full Code Here


      5. One "master input" node that connects to all input nodes, represented with the
         inputPinsInfo array.
      Edges are not created between inetrnal nodes and clocked part inputs.
    */
    private Graph createConnectionsGraph() {
        Graph graph = new Graph();
        Iterator connectionIter = connections.iterator();

        while (connectionIter.hasNext()) {
            Connection connection = (Connection)connectionIter.next();
            Integer part = new Integer(connection.getPartNumber());
            int gatePinNumber = connection.getGatePinNumber();

            switch (connection.getType()) {
                case Connection.TO_INTERNAL:
                    if (isLegalFromPartEdge(connection, part))
                        graph.addEdge(part, getPinInfo(INTERNAL_PIN_TYPE, gatePinNumber));
                    break;

                case Connection.FROM_INTERNAL:
                    if (isLegalToPartEdge(connection, part))
                        graph.addEdge(getPinInfo(INTERNAL_PIN_TYPE, gatePinNumber), part);
                    break;

                case Connection.TO_OUTPUT:
                    if (isLegalFromPartEdge(connection, part))
                        graph.addEdge(part, getPinInfo(OUTPUT_PIN_TYPE, gatePinNumber));
                    break;

                case Connection.FROM_INPUT:
                    if (isLegalToPartEdge(connection, part))
                        graph.addEdge(getPinInfo(INPUT_PIN_TYPE, gatePinNumber), part);
                    break;

                case Connection.FROM_TRUE:
                    if (isLegalToPartEdge(connection, part))
                        graph.addEdge(TRUE_NODE_INFO, part);
                    break;

                case Connection.FROM_FALSE:
                    if (isLegalToPartEdge(connection, part))
                        graph.addEdge(FALSE_NODE_INFO, part);
                    break;

                case Connection.FROM_CLOCK:
                    if (isLegalToPartEdge(connection, part))
                        graph.addEdge(CLOCK_NODE_INFO, part);
                    break;
            }
        }

        // connect the "master part" node to all the parts.
        for (int i = 0; i < partsList.size(); i++)
            graph.addEdge(partsList, new Integer(i));

        // connect all output pins to the "master output" node
        for (int i = 0; i < outputPinsInfo.length; i++)
            graph.addEdge(outputPinsInfo[i], outputPinsInfo);

        // connect the "master input" node to all input pins
        for (int i = 0; i < inputPinsInfo.length; i++)
            graph.addEdge(inputPinsInfo, inputPinsInfo[i]);

        return graph;
    }
View Full Code Here

TOP

Related Classes of Hack.Utilities.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.