/// <summary>
        /// Initializes a new instance of the <see cref="AdjacentNodesGraphBuilder{TNode,TGroup}"/> class that
        /// operates on the given graph.
        /// </summary>
        /// <remarks>
        /// The <paramref name="graph"/> will be <see cref="GraphExtensions.Clear">cleared</see> and re-built
        /// from the data in <see cref="NodesSource"/> and <see cref="GroupsSource"/>
        /// when <see cref="BuildGraph"/> is called.
        /// </remarks>
        public AdjacentNodesGraphBuilder([CanBeNull] IGraph graph = null)
        {
            graphBuilderHelper = new GraphBuilderHelper <TNode, TGroup, TNode>(
                graph ?? new DefaultGraph(),
                this.CreateNodeAndMirrorNode,
                this.UpdateNodeAndCreateMirrorNode,
                this.CreateGroupNode,
                this.UpdateGroupNode,
                this.CreateEdgeAndMirrorEdge,
                this.UpdateEdgeAndCreateMirrorEdge);

            graphBuilderHelper.EdgeCreated += (sender, args) => {
                var eventArgs = new GraphBuilderItemEventArgs <IEdge, object>(args.Graph, args.Item, args.SourceObject);
                foreach (var eventHandler in edgeCreatedHandler)
                {
                    eventHandler(sender, eventArgs);
                }
            };
            graphBuilderHelper.EdgeUpdated += (sender, args) => {
                var eventArgs = new GraphBuilderItemEventArgs <IEdge, object>(args.Graph, args.Item, args.SourceObject);
                foreach (var eventHandler in edgeUpdatedHandler)
                {
                    eventHandler(sender, eventArgs);
                }
            };

            this.graphBuilder                   = new AdjacencyGraphBuilder(graph);
            this.builderNodesSource             = this.graphBuilder.CreateNodesSource <TNode>(Enumerable.Empty <TNode>());
            this.builderNodesSource.NodeCreator = this.graphBuilderHelper.CreateNodeCreator();

            this.builderEdgeCreator = this.graphBuilderHelper.CreateEdgeCreator(true);

            this.builderNodesSource.AddSuccessorsSource(
                dataItem => (this.successorsProvider != null ? this.successorsProvider(dataItem): null),
                this.builderNodesSource,
                this.builderEdgeCreator
                );
            this.builderNodesSource.AddPredecessorsSource(
                dataItem => (this.predecessorsProvider != null ? this.predecessorsProvider(dataItem) : null),
                this.builderNodesSource,
                this.builderEdgeCreator
                );

            this.builderNodesSource.AddSuccessorIds(
                dataItem => this.successorsIdProvider != null ? this.successorsIdProvider(dataItem) : null,
                this.builderEdgeCreator
                );
            this.builderNodesSource.AddPredecessorIds(
                dataItem => this.predecessorsIdProvider != null ? this.predecessorsIdProvider(dataItem) : null,
                this.builderEdgeCreator
                );

            this.builderGroupsSource             = this.graphBuilder.CreateGroupNodesSource <TGroup>(Enumerable.Empty <TGroup>());
            this.builderGroupsSource.NodeCreator = this.graphBuilderHelper.CreateGroupCreator();

            this.mirrorGraph      = new DefaultGraph();
            this.nodeToMirrorNode = new Dictionary <INode, INode>();
        }
示例#2
0
    void Start()
    {
        worldBounds     = transform.Find("WorldBounds").GetChild(0).GetComponent <EdgeCreator>();
        enemyManager    = transform.Find("EnemyManager").GetComponent <EnemyGenerator>();
        ballManager     = transform.Find("BallManager").GetComponent <BallGenerator>();
        lvlDisplay      = transform.Find("GameStatsBar").Find("LevelDisplay").GetComponent <LevelDisplayController>();
        lifeDisplay     = transform.Find("GameStatsBar").Find("LifeDisplay").GetComponent <LifeDisplay>();
        gameOver        = transform.Find("GameOver").gameObject;
        obstacleManager = transform.Find("ObstacleManager").GetComponent <ObstacleGenerator>();
        background      = transform.Find("Background").GetComponent <BackgroundBehavior>();
        /*feedback = transform.Find("FilledFeedback").GetComponent<FillerFeedbackScript>();*/
        progressPie = transform.Find("GameStatsBar").Find("ProgressPie").GetComponent <ProgressPie>();


        // kickstart the first level
        enemyManager.numEnemies = currLevel;
        LevelBegin();
    }
示例#3
0
        ///**
        //* Add an edge from a state to a state with labeling specified
        //* by a formula in propositional logic in prefix form.
        //* @param from  the 'from' state index
        //* @param to    the 'to' state index
        //* @param guard the formula
        //*/
        //public void addEdge(int from, int to, string guard)
        //{

        //    EdgeCreator ec = new EdgeCreator(from, to, _nba);

        //    LTLFormula ltl_guard= LTLPrefixParser.parse(guard, _nba.nba_i_getAPSet());
        //    //    std::cerr << ltl_guard->toStringPrefix() << std::endl;

        //    LTLFormula guard_dnf=ltl_guard.toDNF();
        //    //    std::cerr << guard_dnf->toStringPrefix() << std::endl;

        //    guard_dnf.forEachMonom(ec);
        //}

        /**
         * Add an edge from a state to a state with labeling specified
         * by a formula in propositional logic in prefix form.
         * @param from  the 'from' state index
         * @param to    the 'to' state index
         * @param guard the formula
         */
        public void addEdge(int from, int to, List <Proposition> labels)
        {
            Debug.Assert(labels.Count > 0);
            LTLNode root = createNodeFromLabel(labels[labels.Count - 1]);

            if (labels.Count > 1)
            {
                for (int i = labels.Count - 2; i >= 0; i--)
                {
                    root = new LTLNode(type_t.T_AND, createNodeFromLabel(labels[i]), root);
                }
            }

            EdgeCreator ec = new EdgeCreator(from, to, _nba);

            LTLFormula ltl_guard = new LTLFormula(root, _nba.nba_i_getAPSet());
            //    std::cerr << ltl_guard->toStringPrefix() << std::endl;

            LTLFormula guard_dnf = ltl_guard.toDNF();

            //    std::cerr << guard_dnf->toStringPrefix() << std::endl;

            guard_dnf.forEachMonom(ec);
        }
        /// <summary>
        /// Extract Data provider from the given XML and create and configure a graph builder.
        /// </summary>
        /// <param name="xmlDoc">The XML.</param>
        /// <param name="useSuccessor"></param>
        /// <param name="useIds"></param>
        /// <returns></returns>
        private yWorks.Graph.DataBinding.AdjacencyGraphBuilder CreateOrganizationBuilder(XDocument xmlDoc, bool useSuccessor, bool useIds)
        {
            // extract employees, positions, and business units as enumerables
            var employees                 = xmlDoc.Descendants().Where(p => p.Name.LocalName == "employee");
            var positions                 = employees.Select(employee => employee.Attributes("position").First().Value).Distinct();
            var businessunits             = xmlDoc.Descendants().Where(p => p.Name.LocalName == "businessunit");
            var adjacentNodesGraphBuilder = new yWorks.Graph.DataBinding.AdjacencyGraphBuilder();

            // first node collection: employees

            // create a nodes source which creates nodes from the given employees
            var nodesSource = adjacentNodesGraphBuilder.CreateNodesSource(employees);

            // nodes are grouped in business units
            nodesSource.ParentIdProvider = employee => {
                return(employee.Attributes("businessUnit").First().Value);
            };

            var nodeBrush = new LinearGradientBrush(new PointF(0, 0), new PointF(0, 1), Color.FromArgb(255, 165, 0), Color.FromArgb(255, 237, 204));

            // adjust the size so the node labels fit
            nodesSource.NodeCreator.LayoutProvider = element => {
                var width = 5 + 7 * Math.Max(element.Attributes("name").First().Value.Length, element.Attributes("position").First().Value.Length);
                return(new RectD(0, 0, width, 40));
            };
            nodesSource.NodeCreator.Defaults.Style = new ShapeNodeStyle()
            {
                Pen   = Pens.DarkOrange,
                Brush = nodeBrush,
                Shape = ShapeNodeShape.RoundRectangle
            };
            // set label provider
            var nodeNameLabels = nodesSource.NodeCreator.CreateLabelBinding(element => element.Attributes("name").First().Value);

            nodeNameLabels.Defaults.LayoutParameter = new InteriorStretchLabelModel()
            {
                Insets = new InsetsD(5, 5, 5, 10)
            }.CreateParameter(InteriorStretchLabelModel.Position.Center);
            var nodePositionLabels = nodesSource.NodeCreator.CreateLabelBinding(element => element.Attributes("position").First().Value);

            nodePositionLabels.Defaults.LayoutParameter = new InteriorStretchLabelModel()
            {
                Insets = new InsetsD(5, 20, 5, 5)
            }.CreateParameter(InteriorStretchLabelModel.Position.Center);

            // second nodes collections: positions

            // create nodes source for positions with different style and size
            var positionsSource = adjacentNodesGraphBuilder.CreateNodesSource(positions);

            positionsSource.NodeCreator.Defaults.Size  = new SizeD(100, 60);
            positionsSource.NodeCreator.Defaults.Style = new ShapeNodeStyle( )
            {
                Pen   = Pens.SeaGreen,
                Brush = Brushes.PaleGreen,
                Shape = ShapeNodeShape.RoundRectangle
            };
            var positionLabelCreator = positionsSource.NodeCreator.CreateLabelBinding(position => position.ToString());

            positionLabelCreator.Defaults.LayoutParameter = new InteriorStretchLabelModel()
            {
                Insets = new InsetsD(5)
            }.CreateParameter(InteriorStretchLabelModel.Position.Center);

            // group node collections: business units

            var groupNodesSource = adjacentNodesGraphBuilder.CreateGroupNodesSource(businessunits, (businessunit) => businessunit.Attribute("name").Value);

            groupNodesSource.ParentIdProvider = businessUnit => {
                var parentUnit = (businessUnit.Parent);
                if (parentUnit.Name.LocalName.Equals("businessunit"))
                {
                    return(businessUnit.Parent.Attribute("name").Value);
                }
                return(null);
            };
            groupNodesSource.NodeCreator.Defaults.Size = new SizeD(50, 50);

            var groupNodeBrush = new LinearGradientBrush(new PointF(0.5f, 0), new PointF(0.5f, 1), Color.FromArgb(225, 242, 253), Color.LightSkyBlue);

            groupNodesSource.NodeCreator.Defaults.Style = new ShapeNodeStyle()
            {
                Pen   = Pens.LightSkyBlue,
                Brush = groupNodeBrush
            };
            var groupLabels = groupNodesSource.NodeCreator.CreateLabelBinding(element => element.Attribute("name").Value);

            groupLabels.Defaults.Style = new DefaultLabelStyle()
            {
                TextBrush = Brushes.DarkGray,
                Font      = new Font("Arial", 24)
            };
            groupLabels.Defaults.LayoutParameter = InteriorLabelModel.NorthWest;

            // prepare edge creation
            EdgeCreator <XElement> edgeCreator = new EdgeCreator <XElement> {
                Defaults = { Style               = new PolylineEdgeStyle()
                             {
                                 SmoothingLength = 20, TargetArrow = Arrows.Default
                             } }
            };
            var edgeLabels = edgeCreator.CreateLabelBinding(element => element.Attributes("name").First().Value);

            edgeLabels.Defaults.Style = new DefaultLabelStyle()
            {
                BackgroundBrush = new SolidBrush(Color.FromArgb(225, 242, 253)),
                BackgroundPen   = Pens.LightSkyBlue,
                Insets          = new InsetsD(2),
                Font            = new Font("Arial", 8)
            };
            edgeLabels.Defaults.LayoutParameter = edgeLabelLayoutParameter;

            // configure the successor and predecessor sources
            // for this demo this depends on the chosen settings
            // we configure either successors or predecessors and choose whether we use IDs or the elements themselves to resolve the references
            if (useIds)
            {
                if (useSuccessor)
                {
                    nodesSource.AddSuccessorIds(element => element.Elements(), edgeCreator);
                }
                else
                {
                    nodesSource.AddPredecessorIds(element => {
                        var parentElement = element.Parent;
                        return(parentElement != null && parentElement.Name.LocalName.Equals("employee")? new [] { parentElement } : null);
                    }, edgeCreator);
                }
            }
            else
            {
                if (useSuccessor)
                {
                    nodesSource.AddSuccessorsSource(element => element.Elements(), nodesSource, edgeCreator);
                }
                else
                {
                    nodesSource.AddPredecessorsSource <XElement>(element => {
                        var parentElement = element.Parent;
                        return(parentElement != null && parentElement.Name.LocalName.Equals("employee")? new [] { parentElement } : null);
                    }, nodesSource, edgeCreator);
                }
            }

            // either way: we create edges between the employee and his/her position
            nodesSource.AddSuccessorIds(employee => {
                return(new[] {
                    employee.Attribute("position").Value
                });
            }, new EdgeCreator <XElement>());

            adjacentNodesGraphBuilder.LabelAdded += (sender, args) => {
                var newLabel = true;
            };

            adjacentNodesGraphBuilder.BuildGraph();
            return(adjacentNodesGraphBuilder);
        }
示例#5
0
 // Use this for initialization
 void Start()
 {
     nodes       = new ArrayList();
     edgeCreator = FindObjectOfType <EdgeCreator>();
     UndirectedGraph();
 }
示例#6
0
        ///**
        //* Add an edge from a state to a state with labeling specified
        //* by a formula in propositional logic in prefix form.
        //* @param from  the 'from' state index
        //* @param to    the 'to' state index
        //* @param guard the formula
        //*/
        //public void addEdge(int from, int to, string guard)
        //{
        //    EdgeCreator ec = new EdgeCreator(from, to, _nba);
        //    LTLFormula ltl_guard= LTLPrefixParser.parse(guard, _nba.nba_i_getAPSet());
        //    //    std::cerr << ltl_guard->toStringPrefix() << std::endl;
        //    LTLFormula guard_dnf=ltl_guard.toDNF();
        //    //    std::cerr << guard_dnf->toStringPrefix() << std::endl;
        //    guard_dnf.forEachMonom(ec);
        //}
        /**
         * Add an edge from a state to a state with labeling specified
         * by a formula in propositional logic in prefix form.
         * @param from  the 'from' state index
         * @param to    the 'to' state index
         * @param guard the formula
         */
        public void addEdge(int from, int to, List<Proposition> labels)
        {
            Debug.Assert(labels.Count > 0);
            LTLNode root = createNodeFromLabel(labels[labels.Count - 1]);
            if(labels.Count > 1)
            {
                for (int i = labels.Count-2; i >= 0; i--)
                {
                    root = new LTLNode(type_t.T_AND, createNodeFromLabel(labels[i]), root);
                }
            }

            EdgeCreator ec = new EdgeCreator(from, to, _nba);

            LTLFormula ltl_guard = new LTLFormula(root, _nba.nba_i_getAPSet());
            //    std::cerr << ltl_guard->toStringPrefix() << std::endl;

            LTLFormula guard_dnf = ltl_guard.toDNF();
            //    std::cerr << guard_dnf->toStringPrefix() << std::endl;

            guard_dnf.forEachMonom(ec);
        }