コード例 #1
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;
                    }
                }
            }
        }
コード例 #2
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();
        }