Exemple #1
0
        public override void Update()
        {
            // checks if node is at goal
            if (focus.Cell == CellTypes.GOAL)
            {
                finished = true;
                return;
            }

            foreach (Node child in focus.Children)
            {
                // loops through the already checked nodes to see if child has already been looked at
                if (ContainsNode(CheckedNodes, child))
                {
                    continue;            // skip itteration of the loop since already look
                }
                CheckedNodes.Add(child); // since node not found in the list it is added to the checked nodes list
                focus = child;           // make the child the focus
                return;
            }

            // has no children set target to parent
            if (focus.Parent is Node)
            {
                focus = focus.Parent;
            }
        }
Exemple #2
0
        public override string RunSearch()
        {
            List <Node> frontier = new List <Node>();

            frontier.Add(StartingNode);
            while (frontier.Count != 0)
            {
                // checks if node is at the goal
                if (frontier[0].Cell == CellTypes.GOAL)
                {
                    return(frontier[0].Path + " - GOAL!");
                }
                // gets the children of the current node
                List <Node> children = frontier[0].Children;
                // removes the node from the frontier
                frontier.RemoveAt(0);
                foreach (Node child in children)
                {
                    if (!ContainsNode(CheckedNodes, child))
                    {
                        CheckedNodes.Add(child);
                        frontier.Add(child);
                    }
                }
            }
            return("No solution found");
        }
Exemple #3
0
        public override void Update()
        {
            if (state == States.CHECKING)
            {
                if (frontier.Count == 0)
                {
                    return;
                }
                // checks if node is at the goal
                if (focus.Cell == CellTypes.GOAL)
                {
                    finished = true;
                    return;
                }
                // select node to focus on
                focus = frontier[0];
                int minScore = MovePortential(frontier[0].X, frontier[0].Y);

                for (int i = 1; i < frontier.Count(); i++)
                {
                    int curScore = MovePortential(frontier[i].X, frontier[i].Y);
                    if (curScore < minScore)
                    {
                        minScore = curScore;
                        focus    = frontier[i];
                    }
                }
                // removes the node from the frontier
                frontier.Remove(focus);
                // checks new position is at the goal before expending the node
                if (focus.Cell == CellTypes.GOAL)
                {
                    finished = true;
                    return;
                }

                state = States.EXPANDING;
            }
            else if (state == States.EXPANDING)
            {
                // gets the children of the current node
                List <Node> children = focus.Children;

                foreach (Node child in children)
                {
                    if (!ContainsNode(CheckedNodes, child))
                    {
                        CheckedNodes.Add(child);
                        frontier.Add(child);
                    }
                }

                state = States.CHECKING;
            }
        }
Exemple #4
0
 protected override void OnInitialized()
 {
     if (CheckedNodes != null)
     {
         CheckedKeys = CheckedNodes.Select(node => (int)node.GetType().GetProperty("Id").GetValue(node)).ToArray();
     }
     base.OnInitialized();
     if (!render)
     {
         render = true;
         StateHasChanged();
     }
 }
Exemple #5
0
        /// <summary>
        /// Determine whether or not a brace is considered as restrained. A restrained brace is one that connects directly to a column or to a primary member.
        /// </summary>
        /// <param name="StartBrace">The brace from which to start the chain</param>
        /// <param name="CheckedNodes">The chain of nodes that have already been checked (leave null to start)</param>
        /// <param name="LastNode">The last checked node (leave null to start)</param>
        /// <param name="MoveDownstream">The direction in which to proceed with the checks (true to move away from end to start node of the first beam, false to move in teh other direction)</param>
        /// <returns>The chain of restrained braces</returns>
        public bool CheckBraceRestraint(Beam StartBrace, HashSet <Node> CheckedNodes = null, Node LastNode = null, bool MoveDownstream = false)
        {
            if (CheckedNodes == null)
            {
                CheckedNodes = new HashSet <Node>();
            }

            // Determine which will be the next node depending on the beam orientation and direction of travel
            var currentNode = BeamHelpers.DetermineNextNode(StartBrace, LastNode, MoveDownstream);

            bool output = false;

            if (!CheckedNodes.Contains(currentNode))
            {
                CheckedNodes.Add(currentNode);
                if (currentNode.ConnectedBeams.Any(b => this.PrimaryBeams.Contains(b)) ||
                    currentNode.ConnectedMembers.SelectMany(m => m.Nodes).Any(n => n.ConnectedMembers.Any(m => m.Type == MemberType.COLUMN)))
                {
                    output = true;
                }
                else
                {
                    var nextBraces = currentNode.ConnectedBeams.Where(b => b != StartBrace && b.Spec == BeamSpec.MemberTruss);

                    if (nextBraces.Any())
                    {
                        foreach (var brace in nextBraces)
                        {
                            if (output = this.CheckBraceRestraint(brace, CheckedNodes, currentNode, MoveDownstream))
                            {
                                break;
                            }
                        }
                    }
                    else if (!MoveDownstream)
                    {
                        output = this.CheckBraceRestraint(StartBrace, CheckedNodes, currentNode, true);
                    }
                }
            }

            return(output);
        }
Exemple #6
0
        public override void Update()
        {
            if (state == States.CHECKING)
            {
                if (frontier.Count == 0)
                {
                    return;
                }
                // checks if node is at the goal
                if (focus.Cell == CellTypes.GOAL)
                {
                    finished = true;
                    return;
                }
                // set the focus to the start of the frontier
                focus = frontier[0];
                // removes the node from the frontier
                frontier.RemoveAt(0);
                // checks new position is at the goal before expending the node
                if (focus.Cell == CellTypes.GOAL)
                {
                    finished = true;
                    return;
                }

                state = States.EXPANDING;
            }
            else if (state == States.EXPANDING)
            {
                // gets the children of the current node
                List <Node> children = focus.Children;

                foreach (Node child in children)
                {
                    if (!ContainsNode(CheckedNodes, child))
                    {
                        CheckedNodes.Add(child);
                        frontier.Add(child);
                    }
                }
                state = States.CHECKING;
            }
        }
Exemple #7
0
        public override string RunSearch()
        {
            List <Node> frontier = new List <Node>();

            frontier.Add(StartingNode);
            while (frontier.Count != 0)
            {
                Node selection = frontier[0];
                int  minScore  = MovePortential(frontier[0].X, frontier[0].Y);

                for (int i = 1; i < frontier.Count; i++)
                {
                    int curScore = MovePortential(frontier[i].X, frontier[i].Y);
                    if (curScore < minScore)
                    {
                        minScore  = curScore;
                        selection = frontier[i];
                    }
                }

                // checks if node is at the goal
                if (selection.Cell == CellTypes.GOAL)
                {
                    return(selection.Path + " - GOAL!");
                }
                // gets the children of the current node
                List <Node> children = selection.Children;
                // removes the node from the frontier
                frontier.Remove(selection);
                foreach (Node child in children)
                {
                    if (!ContainsNode(CheckedNodes, child))
                    {
                        CheckedNodes.Add(child);
                        frontier.Add(child);
                    }
                }
            }
            return("No solution found");
        }
Exemple #8
0
        private string RecursiveSearch(Node node)
        {
            // checks if node is at goal
            if (node.Cell == CellTypes.GOAL)
            {
                return(node.Path + " - GOAL!");
            }

            foreach (Node child in node.Children)
            {
                // loops through the already checked nodes to see if child has already been looked at
                if (ContainsNode(CheckedNodes, child))
                {
                    continue;            // skip itteration of the loop since already look
                }
                CheckedNodes.Add(child); // since node not found in the list it is added to the checked nodes list
                string result = RecursiveSearch(child);
                if (result != "No solution found")
                {
                    return(result);
                }
            }
            return("No solution found");
        }
Exemple #9
0
        public override void Update()
        {
            if (state == State.IN)
            {
                // checks if node is at goal
                if (focus[0].Result.Cell == CellTypes.GOAL)
                {
                    finished = true;
                    return;
                }

                state = State.CONTINUE;

                score.Insert(0, new List <SearchResult>());

                foreach (Node child in focus[0].Result.Children)
                {
                    if (!ContainsNode(CheckedNodes, child))
                    {
                        CheckedNodes.Add(child);
                    }
                    // checks node is not in the current path
                    Node parent    = focus[0].Result;
                    bool inCurPath = false;
                    while (parent.Parent is Node)
                    {
                        parent = parent.Parent;
                        if (parent.EqualsPos(child))
                        {
                            inCurPath = true;
                        }
                    }
                    if (!inCurPath)
                    {
                        score[0].Add(new SearchResult(child, MovePortential(child.X, child.Y) + NodeCost(child)));
                    }
                }

                if (score[0].Count == 0)
                {
                    returnValue = int.MaxValue;
                    state       = State.OUT;
                    score.RemoveAt(0);
                }
                return;
            }

            if (state == State.CONTINUE)
            {
                SearchResult best = score[0].OrderBy(n => n.CostLimit).First();
                if (best.CostLimit > limit[0] || best.CostLimit == int.MaxValue)
                {
                    returnValue = best.CostLimit;
                    state       = State.OUT;
                    score.RemoveAt(0);
                    return;
                }
                // enter into next depth
                focus.Insert(0, best);
                limit.Insert(0, (score[0].Count > 1) ? Math.Min(limit[0], score[0].OrderBy(n => n.CostLimit).ElementAt(1).CostLimit) : limit[0]);
                state = State.IN;
                return;
            }

            if (state == State.OUT)
            {
                state = State.CONTINUE;
                focus[0].CostLimit = returnValue;
                focus.RemoveAt(0);
                limit.RemoveAt(0);
            }
        }
Exemple #10
0
        private void gTreeView_AfterCheck(object sender, TreeViewEventArgs e)
        {
            try
            {
                if (e.Node.Checked)
                {
                    bool      found = false;
                    gTreeNode a     = null;
                    foreach (gTreeNode a_loopVariable in CheckedNodes)
                    {
                        a = a_loopVariable;
                        if (e.Node.FullPath == a.FullPath)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        CheckedNodes.Add((gTreeNode)e.Node);
                    }
                }
                else
                {
                    int a = 0;
                    for (a = 0; a < CheckedNodes.Count; a++)
                    {
                        if (e.Node.FullPath == CheckedNodes[a].FullPath)
                        {
                            CheckedNodes.RemoveAt(a);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            if (e.Node.Checked)
            {
                try
                {
                    CheckedNodes.Add((gTreeNode)e.Node);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
            else
            {
                try
                {
                    CheckedNodes.Remove((gTreeNode)e.Node);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }