public DependencyZoneRelationships(DependencyZone zone, DependencyZones allZones)
        {
            this.Zone = zone;
            foreach (DependencyZone aZone in allZones.AllZones)
            {
                HashSet <Vertex> overlap;
                if (aZone != this.Zone)
                {
                    switch (aZone.GetRelationship(this.Zone, out overlap))
                    {
                    case DependencyZone.Relationship.Super:
                        this.SuperZones.Add(aZone.Id, aZone);
                        break;

                    case DependencyZone.Relationship.Sub:
                        this.SubZones.Add(aZone.Id, aZone);
                        break;

                    case DependencyZone.Relationship.Overlap:
                        this.OverlappingZones.Add(aZone.Id, aZone);
                        break;

                    case DependencyZone.Relationship.Alternative:
                        this.AlternativeZones.Add(aZone.Id, aZone);
                        break;
                    }
                }
            }
        }
        public HashSet <Vertex> GetOverlapWithoutEgos(DependencyZone zone)
        {
            HashSet <Vertex> overlap;

            this.GetRelationship(zone, out overlap);
            overlap.ExceptWith(zone.Egos);

            return(overlap);
        }
예제 #3
0
        private void calculateGroups()
        {
            tmpGroups = new ZoneGroup[this.zones.AllZones.Count];
            Parallel.For(0, this.zones.AllZones.Count, i =>
                         //for (int i = 0; i < this.zones.AllZones.Count; i++)
            {
                DependencyZone zone       = this.zones.AllZones[i];
                HashSet <Vertex> vertices = new HashSet <Vertex>();
                switch (this.Strategy)
                {
                case GroupingStrategy.Inner:
                    vertices.UnionWith(zone.InnerZone);
                    break;

                case GroupingStrategy.InnerAndDependentOuter:
                    vertices.UnionWith(zone.InnerZone);
                    vertices.UnionWith(zone.CoLiaisons);
                    break;

                case GroupingStrategy.InnerAndIndependentOuter:
                    vertices.UnionWith(zone.InnerZone);
                    vertices.UnionWith(zone.Liaisons);
                    break;

                case GroupingStrategy.InnerAndOuter:
                    vertices.UnionWith(zone.InnerZone);
                    vertices.UnionWith(zone.OuterZone);
                    break;

                case GroupingStrategy.DependentOuter:
                    vertices.UnionWith(zone.CoLiaisons);
                    break;

                case GroupingStrategy.IndependentOuter:
                    vertices.UnionWith(zone.Liaisons);
                    break;

                case GroupingStrategy.Outer:
                    vertices.UnionWith(zone.OuterZone);
                    break;

                default:
                    break;
                }

                this.tmpGroups[i] = new ZoneGroup(zone);
                foreach (Vertex v in vertices)
                {
                    DependencyZone z = this.zones.GetZone(v);
                    if (z != null)
                    {
                        this.tmpGroups[i].AddZone(z);
                    }
                }
            });
        }
        private void calculateZones(int minSize, int maxSize, bool outerZone)
        {
            int[] ids   = new int[this.Network.Vertices.Values.Count];
            int   index = 0;

            foreach (Vertex v in this.Network.Vertices.Values)
            {
                ids[index] = v.Id;
                index     += 1;
            }
            Array.Sort(ids);

            Dictionary <int, int> indexes = new Dictionary <int, int>();

            for (index = 0; index < ids.Length; index++)
            {
                indexes.Add(ids[index], index);
            }

            this.tmpZones = new DependencyZone[indexes.Count];
            //foreach (int id in ids)
            var options = new ParallelOptions {
                MaxDegreeOfParallelism = Network.MAX_DEGREE_OF_PARALLELISM
            };

            Parallel.ForEach(ids, options, id =>
            {
                DependencyZone newZone = null;

                Vertex v      = this.Network.Vertices[id];
                bool toDetect = true;
                if (this.PROMINENCY_FILTER == ProminencyFilter.AllProminents && v.GetProminency().GetValue() == 0)
                {
                    toDetect = false;
                }
                else if (this.PROMINENCY_FILTER == ProminencyFilter.StrongProminents && v.GetProminency().GetValue() < 1)
                {
                    toDetect = false;
                }
                else if (this.PROMINENCY_FILTER == ProminencyFilter.WeakProminents && (v.GetProminency().GetValue() == 1 || v.GetProminency().GetValue() == 0))
                {
                    toDetect = false;
                }
                if (toDetect)
                {
                    newZone = new DependencyZone(this.Network, v, minSize, maxSize, outerZone);
                    if (newZone.AllVertices.Count == 0)
                    {
                        newZone = null;
                    }
                }
                this.tmpZones[indexes[id]] = newZone;
            });
        }
        public DependencyZone GetZone(Vertex ego)
        {
            if (!this.egoToZoneDictionary.ContainsKey(ego))
            {
                return(null);
            }

            DependencyZone zone = this.egoToZoneDictionary[ego];

            return(zone);
        }
예제 #6
0
        public void CompleteAndFilterDuplicities()
        {
            Dictionary <int, List <ZoneGroup> > groupIndex = new Dictionary <int, List <ZoneGroup> >();
            int id = this.zones.AllZones.Count;

            foreach (ZoneGroup newGroup in this.tmpGroups)
            {
                if (!(this.NonZonesOnly && newGroup.IsZone) && newGroup.Dependency.DependencyScore >= this.DependencyThreshold)
                {
                    int n = newGroup.AllVertices.Count;
                    if (this.DUPLICITY_FILTER == DependencyZone.DuplicityFilter.None) //neni potreba indexovat
                    {
                        id         += 1;
                        newGroup.Id = id;
                        this.AllGroups.Add(newGroup);
                    }
                    else if (n == 1) //neni potreba indexovat
                    {
                        id         += 1;
                        newGroup.Id = id;
                        this.AllGroups.Add(newGroup);
                    }
                    else
                    {
                        List <ZoneGroup> nGroups;
                        if (!groupIndex.TryGetValue(n, out nGroups))
                        {
                            nGroups = new List <ZoneGroup>();
                            groupIndex.Add(n, nGroups);
                        }

                        bool existingGroup = false;
                        foreach (ZoneGroup nGroup in nGroups)
                        {
                            if (DependencyZone.AreEqual(newGroup.AllVertices, nGroup.AllVertices, this.DUPLICITY_FILTER))
                            {
                                existingGroup = true;
                                break;
                            }
                        }
                        if (!existingGroup)
                        {
                            nGroups.Add(newGroup);

                            id         += 1;
                            newGroup.Id = id;
                            this.AllGroups.Add(newGroup);
                        }
                    }
                }
            }
        }
        public bool IsEqualTo(DependencyZone zone, DependencyZone.DuplicityFilter filter)
        {
            switch (filter)
            {
            case DuplicityFilter.MultiEgo:
                return(AreEqual(this.InnerZone, zone.InnerZone, filter));

            case DuplicityFilter.All:
                return(AreEqual(this.AllVertices, zone.AllVertices, filter));

            default:
                return(false);
            }
        }
예제 #8
0
        public ZoneGroup(DependencyZone zone)
        {
            this.zone  = zone;
            this.ego   = zone.Ego;
            this.Zones = new HashSet <DependencyZone>();

            this.egos        = new HashSet <Vertex>();
            this.allVertices = new HashSet <Vertex>();
            this.innerZone   = new HashSet <Vertex>();
            this.outerZone   = new HashSet <Vertex>();
            this.liaisons    = new HashSet <Vertex>();
            this.coLiaisons  = new HashSet <Vertex>();
            this.AddZone(this.Zone);
        }
예제 #9
0
        public void AddZone(DependencyZone zone)
        {
            if (!this.Zones.Contains(zone))
            {
                this.Zones.Add(zone);

                this.Egos.UnionWith(zone.Egos);
                this.AllVertices.UnionWith(zone.AllVertices);

                foreach (Vertex v in zone.InnerZone)
                {
                    this.OuterZone.Remove(v);
                    this.Liaisons.Remove(v);
                    this.CoLiaisons.Remove(v);
                    this.InnerZone.Add(v);
                }

                foreach (Vertex v in zone.OuterZone)
                {
                    if (!this.InnerZone.Contains(v))
                    {
                        this.OuterZone.Add(v);
                        if (zone.Liaisons.Contains(v)) // Liaison
                        {
                            if (!this.CoLiaisons.Contains(v))
                            {
                                this.Liaisons.Add(v);
                            }
                        }
                        else // CoLiaison
                        {
                            this.Liaisons.Remove(v);
                            this.CoLiaisons.Add(v);
                        }
                    }
                }
            }

            if (zone.AllVertices.Count > this.maxZoneCount)
            {
                this.maxZoneCount = zone.AllVertices.Count;
            }

            if (this.isBestEgo(zone.Ego))
            {
                this.ego = zone.Ego;
            }
        }
예제 #10
0
        public Relationship GetRelationship(DependencyZone zone, out HashSet <Vertex> overlap)
        {
            overlap = new HashSet <Vertex>(this.AllVertices.Intersect(zone.AllVertices));

            if (this == zone)
            {
                return(Relationship.Equal);
            }

            if (overlap.Count == 0)
            {
                return(Relationship.None);
            }
            else if (this.AllVertices.Count > zone.AllVertices.Count)
            {
                if (overlap.Count == zone.AllVertices.Count)
                {
                    return(Relationship.Super);
                }
                else
                {
                    return(Relationship.Overlap);
                }
            }
            else if (this.AllVertices.Count < zone.AllVertices.Count)
            {
                if (overlap.Count == this.AllVertices.Count)
                {
                    return(Relationship.Sub);
                }
                else
                {
                    return(Relationship.Overlap);
                }
            }
            else
            {
                if (overlap.Count == zone.AllVertices.Count)
                {
                    return(Relationship.Alternative);;
                }
                else
                {
                    return(Relationship.Overlap);
                }
            }
        }
예제 #11
0
            public ZonesOverlap(DependencyZone zoneA, DependencyZone zoneB)
            {
                this.ZoneA = zoneA;
                this.ZoneB = zoneB;

                if (this.ZoneA.AllVertices.Count >= this.ZoneB.AllVertices.Count)
                {
                    this.LargeZone = this.ZoneA;
                    this.SmallZone = this.ZoneB;
                }
                else
                {
                    this.LargeZone = this.ZoneB;
                    this.SmallZone = this.ZoneA;
                }

                this.Overlap = new HashSet <Vertex>(ZoneA.AllVertices.Intersect(ZoneB.AllVertices));

                if (this.Overlap.Count == this.SmallZone.AllVertices.Count)
                {
                    if (this.Overlap.Count == this.LargeZone.AllVertices.Count)
                    {
                        this.Type = ZonesOverlapType.Equal;
                    }
                    else
                    {
                        this.Type = ZonesOverlapType.Cover;
                    }
                }
                else
                {
                    this.Type = ZonesOverlapType.Overlap;
                }

                this.ZoneADensity = Network.GetDensity(this.ZoneA.AllVertices);
                this.ZoneBDensity = Network.GetDensity(this.ZoneB.AllVertices);
                this.ZoneAExceptOverlapDensity = Network.GetDensity(this.ZoneA.AllVertices.Except(this.Overlap));
                this.ZoneBExceptOverlapDensity = Network.GetDensity(this.ZoneB.AllVertices.Except(this.Overlap));
                this.OverlapDensity            = Network.GetDensity(this.Overlap);
            }
        public void CalculateRelationships()
        {
            if (this.Relationships.Count > 0)
            {
                return;
            }

            DependencyZoneRelationships[] relationshipsArray = new DependencyZoneRelationships[this.AllZones.Count];
            Parallel.For(0, this.AllZones.Count, i =>
            {
                DependencyZone zone = this.AllZones[i];
                DependencyZoneRelationships relationship = new DependencyZoneRelationships(zone, this);
                lock (relLock)
                {
                    relationshipsArray[i] = relationship;
                }
            });

            foreach (DependencyZoneRelationships relationship in relationshipsArray)
            {
                this.Relationships.Add(relationship.Zone, relationship);
            }
        }
예제 #13
0
            public ZoneModularity(DependencyZone zone)
            {
                this.Zone = zone;

                ////////////////////// zakladni modularita
                HashSet <Vertex> boundary = new HashSet <Vertex>();

                foreach (Vertex v in this.Zone.AllVertices)
                {
                    foreach (Vertex adj in v.AdjacentVertices)
                    {
                        if (!this.Zone.AllVertices.Contains(adj))
                        {
                            boundary.Add(v);
                            break;
                        }
                    }
                }

                double         outEdgesWeight = 0;
                HashSet <Edge> inEdges        = new HashSet <Edge>();

                //foreach (Vertex v in this.AllVertices)
                foreach (Vertex v in boundary)
                {
                    double         outEw = 0;
                    HashSet <Edge> inE   = new HashSet <Edge>();
                    foreach (Edge e in v.AdjacentEdges)
                    {
                        if (!this.Zone.AllVertices.Contains(e.GetAdjacent(v)))
                        {
                            outEw += e.Weight;
                        }
                        else
                        {
                            inE.Add(e);
                        }
                    }

                    outEdgesWeight += outEw;
                    foreach (Edge ee in inE)
                    {
                        inEdges.Add(ee);
                    }
                }

                double allEdgesWeight = outEdgesWeight;

                foreach (Edge e in inEdges)
                {
                    allEdgesWeight += e.Weight;
                }

                if (allEdgesWeight == 0)
                {
                    this.BasicValue = 0;
                }
                else
                {
                    this.BasicValue = 1 - outEdgesWeight / allEdgesWeight;
                }

                ///////////////////// modularita inner zony
                boundary = new HashSet <Vertex>();
                foreach (Vertex v in this.Zone.InnerZone)
                {
                    foreach (Vertex adj in v.AdjacentVertices)
                    {
                        if (!this.Zone.InnerZone.Contains(adj))
                        {
                            boundary.Add(v);
                            break;
                        }
                    }
                }

                outEdgesWeight = 0;
                inEdges        = new HashSet <Edge>();
                foreach (Vertex v in boundary)
                {
                    double         outEw = 0;
                    HashSet <Edge> inE   = new HashSet <Edge>();
                    foreach (Edge e in v.AdjacentEdges)
                    {
                        if (!this.Zone.InnerZone.Contains(e.GetAdjacent(v)))
                        {
                            outEw += e.Weight;
                        }
                        else
                        {
                            inE.Add(e);
                        }
                    }

                    outEdgesWeight += outEw;
                    foreach (Edge ee in inE)
                    {
                        inEdges.Add(ee);
                    }
                }

                allEdgesWeight = outEdgesWeight;
                foreach (Edge e in inEdges)
                {
                    allEdgesWeight += e.Weight;
                }

                if (allEdgesWeight == 0)
                {
                    this.InnerValue = 0;
                }
                else
                {
                    this.InnerValue = 1 - outEdgesWeight / allEdgesWeight;
                }

                /////////////////////// modularita zony
                if (this.BasicValue == 0 && this.InnerValue == 0)
                {
                    this.ZoneValue = 0;
                }
                else
                {
                    double bm = this.BasicValue;
                    double im = this.InnerValue;
                    this.ZoneValue = Math.Sqrt((bm * bm + im * im) / 2);
                }
            }
 private void addNewZone(int id, DependencyZone zone)
 {
     zone.Id = id;
     this.AllZones.Add(zone);
     this.egoToZoneDictionary.Add(zone.Ego, zone);
 }
        public void CompleteAndFilterDuplicities()
        {
            Dictionary <int, HashSet <DependencyZone> > zoneIndex = new Dictionary <int, HashSet <DependencyZone> >();

            int id = 0;

            foreach (DependencyZone newZone in this.tmpZones)
            {
                if (newZone != null && newZone.Dependency.DependencyScore >= this.DependencyThreshold)
                {
                    int N = newZone.AllVertices.Count;
                    HashSet <DependencyZone> indexedZonesForN;
                    Vertex firstInnerVertex  = null;
                    Vertex secondInnerVertex = null;
                    if (newZone.InnerZone.Count == 2) //kvuli testu na indexovani
                    {
                        firstInnerVertex  = newZone.InnerZone.ToList()[0];
                        secondInnerVertex = newZone.InnerZone.ToList()[1];
                    }

                    if (this.DUPLICITY_FILTER == DependencyZone.DuplicityFilter.None) //neni potreba indexovat
                    {
                        id += 1;
                        this.addNewZone(id, newZone);
                    }
                    else if (newZone.InnerZone.Count == 1) //neni potreba indexovat
                    {
                        id += 1;
                        this.addNewZone(id, newZone);
                    }
                    else if (newZone.InnerZone.Count == 2 && //neni potreba indexovat
                             !(firstInnerVertex.IsDependentOn(secondInnerVertex) && secondInnerVertex.IsDependentOn(firstInnerVertex)))
                    {
                        id += 1;
                        this.addNewZone(id, newZone);
                    }
                    else if (!zoneIndex.TryGetValue(N, out indexedZonesForN))
                    {
                        indexedZonesForN = new HashSet <DependencyZone>();
                        zoneIndex.Add(N, indexedZonesForN);

                        indexedZonesForN.Add(newZone);

                        id += 1;
                        this.addNewZone(id, newZone);
                    }
                    else
                    {
                        DependencyZone existingZone = null;

                        foreach (DependencyZone nZone in indexedZonesForN)
                        {
                            if (newZone.IsEqualTo(nZone, this.DUPLICITY_FILTER))
                            {
                                existingZone = nZone;
                                break;
                            }
                        }

                        if (existingZone == null)
                        {
                            indexedZonesForN.Add(newZone);

                            id += 1;
                            this.addNewZone(id, newZone);
                        }
                        else
                        {
                            existingZone.AddEgo(newZone.Ego);
                            this.egoToZoneDictionary.Add(newZone.Ego, existingZone);
                        }
                    }
                }
            }

            this.tmpZones = null;
        }