Esempio n. 1
0
        private MTypeMeta create(MType mtype)
        {
            MTypeMeta mtm;

            if (typeMeta.TryGetValue(mtype, out mtm))
            {
                return(mtm);
            }

            int id = nextTypeId();

            mtm = new MTypeMeta(this, mtype, id, false);
            tm.Add(id, mtm);
            typeMeta.Add(mtype, mtm);
            mtm.build();

            HasCommunication   = HasCommunication || mtm.HasCommunication;
            HasDissolution     = HasDissolution || mtm.HasDissolution;
            HasDivision        = HasDivision || mtm.HasDivision;
            HasLinkCreation    = HasLinkCreation || mtm.HasLinkCreation;
            HasLinkDestruction = HasLinkDestruction || mtm.HasLinkDestruction;
            InstanceCount     += mtm.Instances.Length;
            RuleCount         += mtm.RuleSet.Length;
            MTypeCount++;

            return(mtm);
        }
Esempio n. 2
0
        private void AddSymbols(IEnumerable <string> symbolNames, string mtypeName)
        {
            MTypeMeta mtm = kpmm.GetTypeMetaByName(mtypeName, true);

            foreach (string symbol in symbolNames)
            {
                mtm.AddSymbol(symbol);
            }
        }
Esempio n. 3
0
 private void buildDynasty(MTypeMeta typeMeta)
 {
     foreach (MTypeMeta mtm in typeMeta.divisibleTypes)
     {
         if (dynasty.Add(mtm))
         {
             mtm.AddSymbols(typeMeta.Alphabet);
             buildDynasty(mtm);
         }
     }
 }
Esempio n. 4
0
        internal bool IsInDynasty(MTypeMeta typeMeta)
        {
            if (this.HasDivision)
            {
                if (dynasty.Contains(typeMeta))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 5
0
        internal bool DinastyRequiresType(MTypeMeta typeMeta)
        {
            if (this.HasDivision)
            {
                foreach (MTypeMeta mtm in dynasty)
                {
                    //if this is a desired connection
                    if (mtm.IsInterestedIn.Contains(typeMeta))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 6
0
        public MTypeMeta GetTypeMetaByType(MType type, bool createIfNotExists = false)
        {
            if (type == null)
            {
                return(null);
            }
            MTypeMeta mtm = null;

            if (typeMeta.TryGetValue(type, out mtm))
            {
                return(mtm);
            }
            else
            {
                if (createIfNotExists)
                {
                    return(create(type));
                }
            }
            return(null);
        }
Esempio n. 7
0
        public MTypeMeta GetTypeMetaByName(string typeName, bool createIfNotExists = false)
        {
            MType mt = src[typeName];

            if (mt == null)
            {
                return(null);
            }
            MTypeMeta mtm = null;

            if (typeMeta.TryGetValue(mt, out mtm))
            {
                return(mtm);
            }
            else
            {
                if (createIfNotExists)
                {
                    return(create(mt));
                }
            }
            return(null);
        }
Esempio n. 8
0
 public RuleMeta(MTypeMeta mt, Rule rule, int id)
 {
     MTypeMeta = mtm;
     Rule      = rule;
     Id        = id;
 }
 public MInstanceMeta(MTypeMeta tm, MInstance instance, int id)
 {
     MTypeMeta = tm;
     MInstance = instance;
     Id        = id;
 }
Esempio n. 10
0
        internal void postBuild()
        {
            buildDynasty(this);

            foreach (MInstance mi in instances)
            {
                foreach (MInstance miConnection in mi.Connections)
                {
                    MInstanceMeta mim   = kpmm.InstanceRegistry[miConnection];
                    MTypeMeta     mtm   = mim.MTypeMeta;
                    int           count = 0;
                    HasLinksTo.TryGetValue(mtm, out count);
                    HasLinksTo[mtm] = count + 1;
                }
            }

            if (HasLinkOps)
            {
                kpmm.AreLinksNecessary = true;
            }

            foreach (MTypeMeta mtm in IsInterestedIn)
            {
                if (MayConnectTo.Contains(mtm))
                {
                    if (mtm.HasDivision)
                    {
                        Connections[mtm] = -1;
                    }
                    else
                    {
                        Connections[mtm] = mtm.Instances.Length;
                    }
                }
                else
                {
                    int x = 0;
                    HasLinksTo.TryGetValue(mtm, out x);

                    if (x > 0)
                    {
                        if (mtm.HasDivision)
                        {
                            Connections[mtm] = -1;
                        }
                        else
                        {
                            Connections[mtm] = x;
                        }
                    }
                }

                //if the type has more than one instance, then mark the requirement of links
                //links should be considered when they have an effect in the choice of a target for a communication rule
                //or a link rule
                if (mtm.Instances.Length > 1)
                {
                    kpmm.AreLinksNecessary = true;
                }
            }

            foreach (MTypeMeta mtm in HasLinksTo.Keys)
            {
                if (!IsInterestedIn.Contains(mtm))
                {
                    if (mtm.IsInDynasty(this))
                    {
                        Connections[mtm] = -1;
                    }

                    if (mtm.DinastyRequiresType(this))
                    {
                        Connections[mtm] = -1;
                    }
                }
            }
        }
Esempio n. 11
0
        internal void build()
        {
            int id;

            MaxLinks        = 0;
            MaxDivisionRate = 0;
            foreach (MInstance instance in mtype.Instances)
            {
                id = nextInstanceId();
                MInstanceMeta im = new MInstanceMeta(this, instance, id);
                iMeta.Add(id, im);
                kpmm.InstanceRegistry.Add(instance, im);
                AddSymbols(instance.Multiset.Objects);
                if (instance.Connections.Count > MaxLinks)
                {
                    MaxLinks = instance.Connections.Count;
                }
            }
            instances = mtype.Instances.ToArray();

            List <Rule>       rs       = new List <Rule>();
            ExecutionStrategy strategy = mtype.ExecutionStrategy;

            while (strategy != null)
            {
                foreach (Rule r in strategy.Rules)
                {
                    id = nextRuleId();
                    RuleMeta rm = new RuleMeta(this, r, id);
                    rMeta.Add(id, rm);
                    rs.Add(r);
                    kpmm.RuleRegistry[r] = rm;
                    if (r.IsGuarded)
                    {
                        extractGuardAlphabet(r.Guard);
                    }

                    switch (r.Type)
                    {
                    case RuleType.MULTISET_REWRITING: {
                        AddSymbols((r as RewritingRule).Lhs.Objects);
                        AddSymbols((r as RewritingRule).Rhs.Objects);
                    } break;

                    case RuleType.REWRITE_COMMUNICATION: {
                        RewriteCommunicationRule rc = r as RewriteCommunicationRule;
                        AddSymbols(rc.Lhs.Objects);
                        AddSymbols(rc.Rhs.Objects);
                        foreach (TargetedMultiset tarm in rc.TargetRhs.Values)
                        {
                            if (tarm.Target is InstanceIdentifier)
                            {
                                InstanceIdentifier iId = tarm.Target as InstanceIdentifier;
                                if (iId.Indicator == InstanceIndicator.TYPE)
                                {
                                    AddSymbols(tarm.Multiset.Objects, iId.Value);
                                    //add interest in this connection
                                    interests.Add(kpmm.GetTypeMetaByName(iId.Value, true));
                                }
                            }
                        }
                    } break;

                    case RuleType.MEMBRANE_DIVISION: {
                        DivisionRule dr = r as DivisionRule;
                        AddSymbols(dr.Lhs.Objects);
                        foreach (InstanceBlueprint ib in dr.Rhs)
                        {
                            AddSymbols(ib.Multiset.Objects, ib.Type.Name);
                            if (ib.Type == MType)
                            {
                                MaxDivisionRate++;
                                divisibleTypes.Add(this);
                            }
                            else
                            {
                                kpmm.GetTypeMetaByName(ib.Type.Name).MaxDivisionRate++;
                                divisibleTypes.Add(kpmm.GetTypeMetaByType(ib.Type));
                            }
                        }
                    } break;

                    default: {
                        if (r is LinkRule)
                        {
                            LinkRule lr = r as LinkRule;
                            AddSymbols(lr.Lhs.Objects);
                            if (lr.Target is InstanceIdentifier)
                            {
                                InstanceIdentifier iid = lr.Target as InstanceIdentifier;
                                if (iid.Indicator == InstanceIndicator.TYPE)
                                {
                                    MTypeMeta mtm = kpmm.GetTypeMetaByName(iid.Value, true);
                                    interests.Add(mtm);
                                    if (lr.Type == RuleType.LINK_CREATION)
                                    {
                                        mayConnectTo.Add(mtm);
                                    }
                                }
                            }
                        }
                        else if (r is ConsumerRule)
                        {
                            AddSymbols((r as ConsumerRule).Lhs.Objects);
                        }
                    } break;
                    }
                    HasCommunication   = HasCommunication || r.Type == RuleType.REWRITE_COMMUNICATION;
                    HasDivision        = HasDivision || r.Type == RuleType.MEMBRANE_DIVISION;
                    HasDissolution     = HasDissolution || r.Type == RuleType.MEMBRANE_DISSOLUTION;
                    HasLinkCreation    = HasLinkCreation || r.Type == RuleType.LINK_CREATION;
                    HasLinkDestruction = HasLinkDestruction || r.Type == RuleType.LINK_DESTRUCTION;
                }
                strategy = strategy.Next;
            }
            rules = rs.ToArray();
        }