Пример #1
0
 static Searcher()
 {
     FacetHandlers = new java.util.LinkedList();
     FacetHandlers.add(new SimpleFacetHandler(FieldName.CandidateStatus));
     FacetHandlers.add(new CompactMultiValueFacetHandler(FieldName.Industries));
     FacetHandlers.add(new CompactMultiValueFacetHandler(FieldName.DesiredJobTypes));
 }
Пример #2
0
        /**
         * Correct costs of successors of the input vertex using backward star form.
         * (FLOWER)
         *
         * @param vertex
         */
        public void CorrectCostBackward(BaseVertex vertex)
        {
            // 1. initialize the list of vertex to be updated
            var vertexList = new java.util.LinkedList <BaseVertex>();

            vertexList.add(vertex);

            // 2. update the cost of relevant precedents of the input vertex
            while (!vertexList.isEmpty())
            {
                BaseVertex curVertex       = vertexList.remove(0);
                double     costOfCurVertex = startVertexDistanceIndex[curVertex];

                ISet <BaseVertex> preVertexSet = graph.GetPrecedentVertices(curVertex);
                foreach (BaseVertex preVertex in preVertexSet)
                {
                    double costOfPreVertex = startVertexDistanceIndex.ContainsKey(preVertex) ?
                                             startVertexDistanceIndex[preVertex] : Graph.DISCONNECTED;

                    double freshCost = costOfCurVertex + graph.GetEdgeWeight(preVertex, curVertex);
                    if (costOfPreVertex > freshCost)
                    {
                        startVertexDistanceIndex.AddOrReplace(preVertex, freshCost);
                        predecessorIndex.AddOrReplace(preVertex, curVertex);
                        vertexList.add(preVertex);
                    }
                }
            }
        }
Пример #3
0
        /**
         * Calculate the distance from the target vertex to the input
         * vertex using forward star form.
         * (FLOWER)
         *
         * @param vertex
         */
        public Path UpdateCostForward(BaseVertex vertex)
        {
            double cost = Graph.DISCONNECTED;

            // 1. get the set of successors of the input vertex
            ISet <BaseVertex> adjVertexSet = graph.GetAdjacentVertices(vertex);

            // 2. make sure the input vertex exists in the index
            if (!startVertexDistanceIndex.ContainsKey(vertex))
            {
                startVertexDistanceIndex.Add(vertex, Graph.DISCONNECTED);
            }

            // 3. update the distance from the root to the input vertex if necessary
            foreach (BaseVertex curVertex in adjVertexSet)
            {
                // 3.1 get the distance from the root to one successor of the input vertex
                double distance = startVertexDistanceIndex.ContainsKey(curVertex)?
                                  startVertexDistanceIndex[curVertex] : Graph.DISCONNECTED;

                // 3.2 calculate the distance from the root to the input vertex
                distance += graph.GetEdgeWeight(vertex, curVertex);
                //distance += ((VariableGraph)graph).get_edge_weight_of_graph(vertex, curVertex);

                // 3.3 update the distance if necessary
                double costOfVertex = startVertexDistanceIndex[vertex];
                if (costOfVertex > distance)
                {
                    startVertexDistanceIndex.AddOrReplace(vertex, distance);
                    predecessorIndex.AddOrReplace(vertex, curVertex);
                    cost = distance;
                }
            }

            // 4. create the subPath if exists
            Path subPath = null;

            if (cost < Graph.DISCONNECTED)
            {
                subPath = new Path();
                subPath.SetWeight(cost);
                java.util.LinkedList <BaseVertex> vertexList = subPath.GetVertexList();
                vertexList.add(vertex);

                BaseVertex selVertex = predecessorIndex[vertex];
                while (selVertex != null)
                {
                    vertexList.add(selVertex);
                    selVertex = predecessorIndex.GetValueIfExists(selVertex);
                }
            }

            return(subPath);
        }
Пример #4
0
        public java.util.LinkedList <String> GetNodes()
        {
            java.util.LinkedList <String> nodes = new java.util.LinkedList <String>();

            foreach (Edge edge in edges)
            {
                nodes.add(edge.GetFromNode());
            }

            Edge lastEdge = edges.getLast();

            if (lastEdge != null)
            {
                nodes.add(lastEdge.GetToNode());
            }

            return(nodes);
        }
        public java.util.LinkedList <Edge> GetEdges()
        {
            java.util.LinkedList <Edge> edges = new java.util.LinkedList <Edge>();
            foreach (String toNodeLabel in neighbors.Keys)
            {
                edges.add(new Edge(label, toNodeLabel, neighbors[toNodeLabel]));
            }

            return(edges);
        }
Пример #6
0
        public static java.util.List ConvertToJList(List <Token> tokens)
        {
            var list = new java.util.LinkedList();

            foreach (var token in tokens)
            {
                list.add(token);
            }
            return(list);
        }
Пример #7
0
        /**
         * Add a new element in the queue.
         * @param element
         */
        public void Add(E element)
        {
            elementWeightPairList.add(BinLocatePos(element.GetWeight(), isIncremental), element);

            if (limitSize > 0 && elementWeightPairList.size() > limitSize)
            {
                int sizeOfResults = elementWeightPairList.size();
                elementWeightPairList.remove(sizeOfResults - 1);
            }
        }
Пример #8
0
        public Path CloneFrom(int i)
        {
            java.util.LinkedList <Edge> edges = new java.util.LinkedList <Edge>();

            foreach (Edge edge in this.edges.subList(i, this.edges.size()))
            {
                edges.add(edge.Clone());
            }

            return(new Path(edges));
        }
Пример #9
0
        public Path ShallowClone()
        {
            java.util.LinkedList <Edge> edges = new java.util.LinkedList <Edge>();

            foreach (Edge edge in this.edges)
            {
                edges.add(edge);
            }

            return(new Path(edges, this.totalCost));
        }
Пример #10
0
        public Path Clone()
        {
            java.util.LinkedList <Edge> edges = new java.util.LinkedList <Edge>();

            foreach (Edge edge in this.edges)
            {
                edges.add(edge.Clone());
            }

            return(new Path(edges));
        }
Пример #11
0
        public void Test_ForEach_LinkedList()
        {
            java.lang.SystemJ.outJ.println("LinkedList foreach test");


            java.util.LinkedList <String> testArray = new java.util.LinkedList <String>();
            testArray.add("VampireAPI");
            testArray.add("supports");
            testArray.add("foreach statements");
            testArray.add("! Yeah!!!");

            // for count loop
            java.lang.SystemJ.outJ.println("for count loop: ");
            for (int i = 0; i < testArray.size(); i++)
            {
                java.lang.SystemJ.outJ.print(testArray.get(i));
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();

            // for iterator loop
            java.lang.SystemJ.outJ.println("for iterator loop: ");
            for (java.util.Iterator <String> it = testArray.iterator(); it.hasNext();)
            {
                java.lang.SystemJ.outJ.print(it.next());
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();

            // foreach loop
            java.lang.SystemJ.outJ.println("foreach loop: ");
            foreach (String text in testArray)
            {
                java.lang.SystemJ.outJ.print(text);
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();


            Assert.True(true, "compiler OK");
        }
Пример #12
0
        /**
         * Note that, the source should not be as same as the sink! (we could extend
         * this later on)
         *
         * @param sourceVertex
         * @param sinkVertex
         * @return
         */
        public Path GetShortestPath(BaseVertex sourceVertex, BaseVertex sinkVertex)
        {
            DetermineShortestPaths(sourceVertex, sinkVertex, true);
            //
            java.util.LinkedList <BaseVertex> vertexList = new java.util.LinkedList <BaseVertex>();
            double weight = startVertexDistanceIndex.ContainsKey(sinkVertex) ?
                            startVertexDistanceIndex[sinkVertex] : Graph.DISCONNECTED;

            if (weight != Graph.DISCONNECTED)
            {
                BaseVertex curVertex = sinkVertex;
                do
                {
                    vertexList.add(curVertex);
                    curVertex = predecessorIndex[curVertex];
                } while (curVertex != null && curVertex != sourceVertex);
                vertexList.add(sourceVertex);
                vertexList.reverse();
            }
            return(new Path(vertexList, weight));
        }
Пример #13
0
 public java.util.LinkedList <Edge> RemoveEdgesToNode(String label)
 {
     java.util.LinkedList <Edge> edges = new java.util.LinkedList <Edge>();
     foreach (Node node in nodes.Values)
     {
         if (node.GetAdjacencyList().Contains(label))   // TODO: perfomance ... Contains in collection ...
         {
             double weight = node.RemoveEdge(label);
             edges.add(new Edge(node.GetLabel(), label, weight));
         }
     }
     return(edges);
 }
Пример #14
0
        public Path CloneTo(int i)
        {
            java.util.LinkedList <Edge> edges = new java.util.LinkedList <Edge>();
            int l = this.edges.size();

            if (i > l)
            {
                i = l;
            }

            //for (Edge edge : this.edges.subList(0,i)) {
            for (int j = 0; j < i; j++)
            {
                edges.add(this.edges.get(j).Clone());
            }

            return(new Path(edges));
        }
Пример #15
0
 private void  removeItem(System.Object item)
 {
     if (items != null)
     {
         List temp   = new LinkedList();
         List litems = (List)item;
         for (int idx = 0; idx < litems.size(); idx++)
         {
             System.Object tmpItem = litems.get(idx);
             if (!tmpItem.Equals(item))
             {
                 temp.add(tmpItem);
             }
         }
         items = temp.toArray();
         fireContentsChanged(this, 0, items.Length);
     }
 }
Пример #16
0
        protected internal virtual void  createPrimitives(ViewGraphNode root)
        {
            LinkedList queue = new LinkedList();

            queue.add(root);
            while (!queue.isEmpty())
            {
                ViewGraphNode act = (ViewGraphNode)queue.remove(0);
                Shape         s   = null;
                if (act.Shape == null)
                {
                    s = makeShapeFromNode(act, queue);
                }
                else
                {
                    s = act.Shape;
                }
                if (act.ParentsChecked)
                {
                    continue;
                }
                act.ParentsChecked = true;
                for (Iterator it = act.Parents.iterator(); it.hasNext();)
                {
                    ViewGraphNode n  = (ViewGraphNode)it.next();
                    Shape         s1 = n.Shape;
                    if (s1 == null)
                    {
                        s1 = makeShapeFromNode(n, queue);
                    }
                    ConnectorLine line = new ConnectorLine(s1, s);
                    line.Color = System.Drawing.Color.Blue;
                    if (n.ReteNode is BaseJoin)
                    {
                        line.Color = System.Drawing.Color.Red;
                    }
                    addPrimitive(line);
                }
            }
        }
Пример #17
0
        protected internal virtual Shape makeShapeFromNode(ViewGraphNode act, LinkedList queue)
        {
            System.Drawing.Color bg = getBackgroundColorForNode(act);
            System.Drawing.Color border = getBorderColorForNode(act);
            System.String desc = "";
            BaseNode reteNode = act.ReteNode;
            HashSet terminalNodes = new HashSet();
            getCorrespondingTerminalNodes(act, terminalNodes);
            if (reteNode != null)
                desc = reteNode.NodeId.ToString();
            Shape s;
            if (reteNode == null)
            {
                // ROOT NODE
                s = new Ellipse();
            }
            else if (reteNode is BaseJoin || act.ReteNode is BaseAlpha2)
            {
                s = new Trapezoid();
            }
            else if (reteNode is TerminalNode)
            {
                s = new RoundedRectangle();
            }
            else if (reteNode is LIANode)
            {
                s = new Ellipse();
            }
            else
            {
                s = new Rectangle();
            }
            s.Bgcolor = bg;
            s.Bordercolor = border;
            //UPGRADE_WARNING: Narrowing conversions may produce unexpected results in C#. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042"'
            int x = (spaceHorizontal / 2) + (int) ((float) (act.X * (spaceHorizontal + nodeHorizontal)) / 2.0);
            int y = (spaceVertical / 2) + act.Y * (spaceVertical + nodeVertical);
            System.String key = x + "," + y;
            // if there is already a node at the given location, we shift it right
            while (this.coordinates.ContainsKey(key))
            {
                x = x + ((spaceHorizontal + nodeHorizontal) * 2);
                key = x + "," + y;
            }
            SupportClass.PutElement(coordinates, key, s);
            s.X = x;
            s.Y = y;
            s.Width = nodeHorizontal;
            s.Height = nodeVertical;
            System.String longdesc = "";
            if (reteNode == null)
            {
                longdesc = "Root Node";
            }
            else
            {
                longdesc = "ID:" + reteNode.NodeId + "  NodeType:" + reteNode.GetType().FullName;
                longdesc += "  Details:" + reteNode.toPPString();
            }
            longdesc += "  Rules:";
            Iterator iter = terminalNodes.iterator();
            while (iter.hasNext())
            {
                TerminalNode t = (TerminalNode) iter.next();

                longdesc += t.Rule.Name;
                if (iter.hasNext())
                    longdesc += ";";
            }
            s.LongDescription = longdesc;
            if (reteNode is LIANode)
                s.incWidth(- nodeHorizontal / 3);
            s.Text = desc;
            act.Shape = s;
            addPrimitive(s);
            for (Iterator it = act.Successors.iterator(); it.hasNext(); )
            {
                ViewGraphNode n = (ViewGraphNode) it.next();
                queue.add(n);
            }
            return s;
        }
Пример #18
0
 protected internal virtual void createPrimitives(ViewGraphNode root)
 {
     LinkedList queue = new LinkedList();
     queue.add(root);
     while (!queue.isEmpty())
     {
         ViewGraphNode act = (ViewGraphNode) queue.remove(0);
         Shape s = null;
         if (act.Shape == null)
         {
             s = makeShapeFromNode(act, queue);
         }
         else
         {
             s = act.Shape;
         }
         if (act.ParentsChecked)
             continue;
         act.ParentsChecked = true;
         for (Iterator it = act.Parents.iterator(); it.hasNext(); )
         {
             ViewGraphNode n = (ViewGraphNode) it.next();
             Shape s1 = n.Shape;
             if (s1 == null)
                 s1 = makeShapeFromNode(n, queue);
             ConnectorLine line = new ConnectorLine(s1, s);
             line.Color = System.Drawing.Color.Blue;
             if (n.ReteNode is BaseJoin)
                 line.Color = System.Drawing.Color.Red;
             addPrimitive(line);
         }
     }
 }
Пример #19
0
 static Searcher()
 {
     FacetHandlers = new java.util.LinkedList();
     FacetHandlers.add(new CompactMultiValueFacetHandler(FieldName.Industries));
     FacetHandlers.add(new CompactMultiValueFacetHandler(FieldName.JobTypes));
 }
Пример #20
0
        /**
         * Computes the K shortest paths in a graph from node s to node t using Yen's algorithm
         *
         * @param graph         the graph on which to compute the K shortest paths from s to t
         * @param sourceLabel   the starting node for all of the paths
         * @param targetLabel   the ending node for all of the paths
         * @param K             the number of shortest paths to compute
         * @return              a list of the K shortest paths from s to t, ordered from shortest to longest
         */
        public IList <Path> Ksp(Graph graph, String sourceLabel, String targetLabel, int K)
        {
            // Initialize containers for candidate paths and k shortest paths
            List <Path> ksp = new List <Path>();

            java.util.PriorityQueue <Path> candidates = new java.util.PriorityQueue <Path>();

            //try {
            /* Compute and add the shortest path */
            Path kthPath = Dijkstra.ShortestPath(graph, sourceLabel, targetLabel);

            ksp.Add(kthPath);

            /* Iteratively compute each of the k shortest paths */
            for (int k = 1; k < K; k++)
            {
                // Get the (k-1)st shortest path
                Path previousPath = ksp[k - 1];

                /* Iterate over all of the nodes in the (k-1)st shortest path except for the target node; for each node,
                 * (up to) one new candidate path is generated by temporarily modifying the graph and then running
                 * Dijkstra's algorithm to find the shortest path between the node and the target in the modified
                 * graph */
                for (int i = 0; i < previousPath.Size(); i++)
                {
                    // Initialize a container to store the modified (removed) edges for this node/iteration
                    java.util.LinkedList <Edge> removedEdges = new java.util.LinkedList <Edge>();

                    // Spur node = currently visited node in the (k-1)st shortest path
                    String spurNode = previousPath.GetEdges().get(i).GetFromNode();

                    // Root path = prefix portion of the (k-1)st path up to the spur node
                    Path rootPath = previousPath.CloneTo(i);

                    /* Iterate over all of the (k-1) shortest paths */
                    foreach (Path p in ksp)
                    {
                        Path stub = p.CloneTo(i);
                        // Check to see if this path has the same prefix/root as the (k-1)st shortest path
                        if (rootPath.Equals((object)stub))
                        {
                            /* If so, eliminate the next edge in the path from the graph (later on, this forces the spur
                             * node to connect the root path with an un-found suffix path) */
                            Edge re = p.GetEdges().get(i);
                            graph.RemoveEdge(re.GetFromNode(), re.GetToNode());
                            removedEdges.add(re);
                        }
                    }

                    /* Temporarily remove all of the nodes in the root path, other than the spur node, from the graph */
                    foreach (Edge rootPathEdge in rootPath.GetEdges())
                    {
                        String rn = rootPathEdge.GetFromNode();
                        if (!rn.Equals(spurNode))
                        {
                            removedEdges.addAll(graph.RemoveNode(rn));
                        }
                    }

                    // Spur path = shortest path from spur node to target node in the reduced graph
                    Path spurPath = Dijkstra.ShortestPath(graph, spurNode, targetLabel);

                    // If a new spur path was identified...
                    if (spurPath != null)
                    {
                        // Concatenate the root and spur paths to form the new candidate path
                        Path totalPath = rootPath.Clone();
                        totalPath.AddPath(spurPath);

                        // If candidate path has not been generated previously, add it
                        if (!candidates.contains(totalPath))
                        {
                            candidates.add(totalPath, totalPath.GetTotalCost());
                        }
                    }

                    // Restore all of the edges that were removed during this iteration
                    graph.AddEdges(removedEdges);
                }

                /* Identify the candidate path with the shortest cost */
                bool isNewPath;
                do
                {
                    kthPath   = candidates.poll();
                    isNewPath = true;
                    if (kthPath != null)
                    {
                        foreach (Path p in ksp)
                        {
                            // Check to see if this candidate path duplicates a previously found path
                            if (p.Equals(kthPath))
                            {
                                isNewPath = false;
                                break;
                            }
                        }
                    }
                } while(!isNewPath);

                // If there were not any more candidates, stop
                if (kthPath == null)
                {
                    break;
                }

                // Add the best, non-duplicate candidate identified as the k shortest path
                ksp.Add(kthPath);
            }
            //} catch (Exception e) {
            //    SystemOut.println(e);
            //    e.printStackTrace();
            //}

            // Return the set of k shortest paths
            return(ksp);
        }
Пример #21
0
 private void removeItem(System.Object item)
 {
     if (items != null)
     {
         List temp = new LinkedList();
         List litems = (List) item;
         for (int idx = 0; idx < litems.size(); idx++)
         {
             System.Object tmpItem = litems.get(idx);
             if (!tmpItem.Equals(item))
             {
                 temp.add(tmpItem);
             }
         }
         items = temp.toArray();
         fireContentsChanged(this, 0, items.Length);
     }
 }
Пример #22
0
 static Searcher()
 {
     FacetHandlers = new java.util.LinkedList();
     FacetHandlers.add(new SimpleFacetHandler(FieldName.ItemType));
 }
Пример #23
0
        protected internal virtual Shape makeShapeFromNode(ViewGraphNode act, LinkedList queue)
        {
            System.Drawing.Color bg       = getBackgroundColorForNode(act);
            System.Drawing.Color border   = getBorderColorForNode(act);
            System.String        desc     = "";
            BaseNode             reteNode = act.ReteNode;
            HashSet terminalNodes         = new HashSet();

            getCorrespondingTerminalNodes(act, terminalNodes);
            if (reteNode != null)
            {
                desc = reteNode.NodeId.ToString();
            }
            Shape s;

            if (reteNode == null)
            {
                // ROOT NODE
                s = new Ellipse();
            }
            else if (reteNode is BaseJoin || act.ReteNode is BaseAlpha2)
            {
                s = new Trapezoid();
            }
            else if (reteNode is TerminalNode)
            {
                s = new RoundedRectangle();
            }
            else if (reteNode is LIANode)
            {
                s = new Ellipse();
            }
            else
            {
                s = new Rectangle();
            }
            s.Bgcolor     = bg;
            s.Bordercolor = border;
            //UPGRADE_WARNING: Narrowing conversions may produce unexpected results in C#. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042"'
            int x = (spaceHorizontal / 2) + (int)((float)(act.X * (spaceHorizontal + nodeHorizontal)) / 2.0);
            int y = (spaceVertical / 2) + act.Y * (spaceVertical + nodeVertical);

            System.String key = x + "," + y;
            // if there is already a node at the given location, we shift it right
            while (this.coordinates.ContainsKey(key))
            {
                x   = x + ((spaceHorizontal + nodeHorizontal) * 2);
                key = x + "," + y;
            }
            SupportClass.PutElement(coordinates, key, s);
            s.X      = x;
            s.Y      = y;
            s.Width  = nodeHorizontal;
            s.Height = nodeVertical;
            System.String longdesc = "";
            if (reteNode == null)
            {
                longdesc = "Root Node";
            }
            else
            {
                longdesc  = "ID:" + reteNode.NodeId + "  NodeType:" + reteNode.GetType().FullName;
                longdesc += "  Details:" + reteNode.toPPString();
            }
            longdesc += "  Rules:";
            Iterator iter = terminalNodes.iterator();

            while (iter.hasNext())
            {
                TerminalNode t = (TerminalNode)iter.next();

                longdesc += t.Rule.Name;
                if (iter.hasNext())
                {
                    longdesc += ";";
                }
            }
            s.LongDescription = longdesc;
            if (reteNode is LIANode)
            {
                s.incWidth(-nodeHorizontal / 3);
            }
            s.Text    = desc;
            act.Shape = s;
            addPrimitive(s);
            for (Iterator it = act.Successors.iterator(); it.hasNext();)
            {
                ViewGraphNode n = (ViewGraphNode)it.next();
                queue.add(n);
            }
            return(s);
        }
Пример #24
0
 public void Add(Edge edge)
 {
     edges.add(edge);
     totalCost += edge.GetWeight();
 }