Esempio n. 1
0
        //
        // Producer method
        //
        public void WriteEdge(PebblerHyperEdge <A> edgeToWrite)
        {
            // Enter synchronization block
            lock (this)
            {
                if (readerFlag)
                {
                    // Wait until ReadEdge is done consuming.
                    try
                    {
                        // Wait for the Monitor.Pulse in Read
                        Monitor.Wait(this);
                    }
                    catch (SynchronizationLockException e)
                    {
                        System.Diagnostics.Debug.WriteLine(e);
                    }
                }

                writerFlag = true;

                // Produce
                edgeList.Add(edgeToWrite);

                // Reset the state flag to say producing is done.
                writerFlag = false;

                // Pulse tells Read that Write is complete.
                Monitor.Pulse(this);
            }
        }
Esempio n. 2
0
        //
        // Add the PebblerHyperEdge to all source node hash values
        //
        public void Put(PebblerHyperEdge <A> edge)
        {
            // Analyze the edge to determine if it is a mixed edge; all edges are
            // such that the target is greater than or less than all source nodes
            // Find the minimum non-intrinsic node (if it exists)
            edge.sourceNodes.Sort();
            int minSrc = edge.sourceNodes.Max();

            foreach (int src in edge.sourceNodes)
            {
                if (!graph.vertices[src].data.IsIntrinsic() || !graph.vertices[src].data.IsAxiomatic())
                {
                    minSrc = src;
                }
            }
            int maxSrc = edge.sourceNodes.Max();

            if (minSrc < edge.targetNode && edge.targetNode < maxSrc)
            {
                throw new ArgumentException("A mixed edge was pebbled as valid: " + edge);
            }

            long hashVal = (edge.targetNode % TABLE_SIZE);

            if (table[hashVal] == null)
            {
                table[hashVal] = new List <PebblerHyperEdge <A> >();
            }

            Utilities.AddUnique <PebblerHyperEdge <A> >(table[hashVal], edge);

            size++;
        }
Esempio n. 3
0
        //
        // Consumer method
        //
        public PebblerHyperEdge <A> ReadEdge()
        {
            // If writing is known to be done and the list is empty, this is an error
            if (IsReadingAndWritingComplete())
            {
                return(null);
            }

            PebblerHyperEdge <A> readEdge = null;

            // Enter synchronization block
            lock (this)
            {
                // Wait until WriteEdge produces OR is done producing a new edge
                if (writerFlag || !edgeList.Any())
                {
                    try
                    {
                        // Waits for the Monitor.Pulse in WriteEdge
                        // Add a timeout in case nothing is ever written...
                        Monitor.Wait(this /* , new TimeSpan(1000)*/);

                        // If this timed out, return invalid
                        //if (!edgeList.Any()) return null;
                    }
                    catch (SynchronizationLockException e)
                    {
                        System.Diagnostics.Debug.WriteLine(e);
                    }
                }

                readerFlag = true;

                // Consume the edge
                readEdge = edgeList[0];
                edgeList.RemoveAt(0);

                // Reset the state flag to say producing is done.
                readerFlag = false;

                // Pulse tells WriteEdge that ReadEdge is done.
                Monitor.Pulse(this);
            }

            return(readEdge);
        }
Esempio n. 4
0
        //public void SetColor(PebblerColorType color)
        //{
        //    pebbleColor = color;
        //}

        // The source nodes and target must be the same for equality.
        public override bool Equals(object obj)
        {
            PebblerHyperEdge <A> thatEdge = obj as PebblerHyperEdge <A>;

            if (thatEdge == null)
            {
                return(false);
            }
            foreach (int src in sourceNodes)
            {
                if (!thatEdge.sourceNodes.Contains(src))
                {
                    return(false);
                }
            }
            return(targetNode == thatEdge.targetNode);
        }
Esempio n. 5
0
        public override string ToString()
        {
            String retS = "";

            for (int ell = 0; ell < TABLE_SIZE; ell++)
            {
                if (table[ell] != null)
                {
                    retS += ell + ":\n";
                    foreach (PebblerHyperEdge <A> PebblerHyperEdge in table[ell])
                    {
                        retS += PebblerHyperEdge.ToString() + "\n";
                    }
                }
            }

            return(retS);
        }
Esempio n. 6
0
 public void AddEdge(PebblerHyperEdge <A> edge)
 {
     edges.Add(edge);
 }