예제 #1
0
        public override IGate Simplify()
        {
            IGate result = this;

            result = SimplifyNormalize(result);

            if (result.Type.IsFixed())
            {
                return(result);
            }

            if (IsProductOfInputs)
            {
                result = SimplifyProductOfInputs(result.GetProduct());
            }
            else
            {
                result = SimplifyMultiplicate(result);
                result = Gate.Simplify(result);
            }


            Gate.TraceSimplify(this, result, "simplify AND");

            return(result);
        }
예제 #2
0
        private IGate SimplifyNormalize(IGate gate)
        {
            var list   = new List <IGate>();
            var inputs = gate.GetInputs();

            foreach (var e in gate.GetInputs())
            {
                if (e.Type == GateType.AND)
                {
                    list.AddRange(e.GetInputs());
                }
                else if (e.Type.IsFixed())
                {
                    if (e is FalseGate)
                    {
                        return(e);
                    }
                }
                else
                {
                    list.Add(e);
                }
            }

            var and = new ANDGate();

            and.AddInputRange(list);

            return(and);
        }
예제 #3
0
        public static IGate SimplifyMultiplicate(IGate g)
        {
            Debug.Assert(g.Type == GateType.AND);

            var or = new ORGate();

            or.AddInput(new TrueGate());

            IGate r = or;

            foreach (var e in g.GetInputs())
            {
                if (e.Type == GateType.OR)
                {
                    r = Gate.Multiply(r.GetInputs(), e.GetInputs());
                }
                else
                {
                    r = Gate.Multiply(r.GetInputs(), e);
                }
            }

            r = Gate.Simplify(r);

            TraceSimplify(g, r, "simplify AND");

            return(r);
        }
예제 #4
0
 public MembershipController(ISecurityUserReader securityUserReader, IGate gate, IAuthenticationService authenticationService, IDinnerReader dinnerReader)
 {
     _securityUserReader = securityUserReader;
     _gate = gate;
     _authenticationService = authenticationService;
     _dinnerReader          = dinnerReader;
 }
예제 #5
0
 public DinnerController(IGate gate, IDinnerReader dinnerReader, IProfileReader profileReader, ISecurityUserReader securityUserReader)
 {
     _gate = gate;
     _dinnerReader = dinnerReader;
     _profileReader = profileReader;
     _securityUserReader = securityUserReader;
 }
예제 #6
0
        //Check of er een loop in zit
        private bool IsComponentLoop(IGate toCheck)
        {
            //Een lijst van nodes die al gecheked zijn
            List <IGate> checkedNodes = new List <IGate>();
            //De inputs van de nodes die gechecked moeten worden
            Stack <IGate> toCheckStack = new Stack <IGate>(toCheck.GetInputs());

            //Zolang er inputs zijn die gechecked moeten worden
            while (toCheckStack.Count() > 0)
            {
                //Krijg de eerstvolgende input
                IGate current = toCheckStack.Pop();
                checkedNodes.Add(current);

                //Als er een loop is, return true
                if (current.GetInputs().Contains(toCheck))
                {
                    return(true);
                }

                foreach (IGate n in current.GetInputs())
                {
                    if (!checkedNodes.Contains(n))
                    {
                        toCheckStack.Push(n);
                    }
                }
            }

            //Alles is goed
            return(false);
        }
예제 #7
0
        private IGate EvaluateRecurse(ICodeLabelEvaluator cg, IGate g)
        {
            if (g.Type == GateType.Input)
            {
                if (g is LabelGate)
                {
                    var lg = (LabelGate)g;
                    lg.Label.Evaluate(cg);
                }
            }
            else
            {
                var list = new List <IGate>();
                foreach (var i in g.GetInputs())
                {
                    var u = i;
                    var l = _gc.GetScheduledLabel(u);
                    if (null != l)
                    {
                        u = l;
                    }
                    else
                    {
                        u = EvaluateRecurse(cg, u);
                    }

                    list.Add(u);
                }

                g = SMG.Common.Gate.Compose(g.Type, list);
            }

            return(g);
        }
예제 #8
0
        /// <summary>
        /// Is the gate applicable for the current context
        /// </summary>
        /// <param name="gate">gate to check</param>
        /// <returns>true if applicable, false otherwise</returns>
        private bool IsGateApplicableInternal(IGate gate)
        {
            bool grantAccess = gate.IsGateEnabled;

            // If the gate is disabled but has been asked to be enabled through settings.
            if (m_settings?.GatesToggleEnabled?.Contains(gate.Name) ?? false)
            {
                grantAccess = true;
                ULSLogging.LogTraceTag(0x2382104e /* tag_967bo */, Categories.GateSelection, Levels.Verbose, "Enabling gate '{0}' through BRS that was disabled using gate toggle setting",
                                       gate.Name);
            }

            grantAccess = grantAccess && DoesHostEnvironmentHaveAccess(gate);
            grantAccess = grantAccess && DoesServiceHaveAccess(gate);
            grantAccess = grantAccess && DoesIPAddressHaveAccess(gate);
            grantAccess = grantAccess && DoesMarketHaveAccess(gate);
            grantAccess = grantAccess && DoesEnvironmentHaveAccess(gate);
            grantAccess = grantAccess && DoesBrowserHaveAccess(gate);
            grantAccess = grantAccess && DoesClientHaveAccess(gate);
            grantAccess = grantAccess && DoesUserHaveAccess(gate);
            grantAccess = grantAccess && IsCurrentDateEnabled(gate);
            grantAccess = grantAccess && DoQueryParametersHaveAccess(gate);
            grantAccess = grantAccess && DoesCloudContextHaveAccess(gate);

            if (gate.ExperimentInfo != null)
            {
                grantAccess = grantAccess && ExperimentContext.IsExperimentalGateApplicable(gate);
            }

            return(grantAccess);
        }
예제 #9
0
 public static void TraceCompose(IGate a, IGate r, string format, params object[] args)
 {
     if (TraceFlags.ShowCompose)
     {
         Log.TraceGateOp2(a, r, format, args);
     }
 }
예제 #10
0
파일: Log.cs 프로젝트: thomas13335/smg
 public static void TraceGuard(IGate gate1, IGate gate2, string p)
 {
     if (TraceFlags.ShowGuard)
     {
         TraceGateOp2(gate1, gate2, p);
     }
 }
예제 #11
0
        /// <summary>
        /// Sets the alias for an expression to an existing label.
        /// </summary>
        /// <param name="stage">The stage where to evaluate the gate.</param>
        /// <param name="e">The gate.</param>
        /// <param name="label">The label to refer to.</param>
        /// <param name="pstage"></param>
        public void SetAlias(int stage, IGate e, IGate r, int pstage)
        {
            e = e.Simplify();

            var id = GetCodeLabelIdentifier(stage, e);

            Debug.Assert(_gatemap.ContainsKey(r.ID));

            CodeLabel label;

            if (!_gatemap.TryGetValue(r.ID, out label))
            {
                throw new InvalidOperationException("label for gate not found.");
            }

            if (!_labels.ContainsKey(id))
            {
                _labels[id] = label;

                Gate.TraceLabel(e, label.Gate, stage + " alias");
            }
            else
            {
                //throw new Exception("label already defined.");
                Trace("label {0} already defined {0}, {1}", e, label.Gate);
            }


            AddToGateMap(e, label);
        }
예제 #12
0
 public static void TraceDependencies(IGate a, IGate r, string format, params object[] args)
 {
     if (TraceFlags.ShowDepencencyAnalysis)
     {
         Log.TraceGateOp2(a, r, format, args);
     }
 }
예제 #13
0
파일: Log.cs 프로젝트: thomas13335/smg
        public static void TraceGateOp3(IGate a, IGate b, IGate r, string format, params object[] args)
        {
            var text = string.Format(format, args);
            var line = a.ToString().PadRight(21) + " || " + b.ToString().PadRight(21) + " " + text.PadRight(20) + " ==> " + r.ToString();

            Trace("    {0}", line);
        }
예제 #14
0
        /// <summary>
        /// Replaces all variables not found in a guard with one.
        /// </summary>
        /// <param name="gate"></param>
        /// <param name="monitor"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private IGate ReplaceNonGuardVariables(IGate gate, Guard monitor)
        {
            // get variables referenced in the condition
            var variables = monitor.PreCondition
                            .SelectAll(e => e is IVariableCondition)
                            .OfType <IVariableCondition>()
                            .Select(u => u.Variable)
                            .Distinct();

            var vset = new HashSet <Variable>(variables);

            // TraceDependencies("monitor variables: {0}", variables.ToSeparatorList());

            IGate r = gate
                      .Replace(g =>
            {
                if (g is IVariableCondition)
                {
                    var vc = (IVariableCondition)g;
                    if (!vset.Contains(vc.Variable))
                    {
                        g = Gate.Constant(true);
                    }
                }

                return(g);
            })
                      .Simplify();

            return(r);
        }
예제 #15
0
        /// <summary>
        /// Replacer function for gate to code replacement.
        /// </summary>
        /// <param name="stage"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private IGate ReplaceWithCodeLabel(int stage, IGate e)
        {
            if (e is LabelGate)
            {
                return(e);
            }

            var e0 = e;

            e = e.Simplify();

            int maxstage = stage;

            var children = e.SelectAll().OfType <LabelGate>();

            if (children.Any())
            {
                maxstage = children.Max(u => u.Label.Stage);
            }

            var label = AddCodeLabel(maxstage, e, false);

            if (e.Type == GateType.Input)
            {
                // leaf level of replacement, just refer to the new variable.
                e = label.Gate;
                // Gate.TraceLabel(e0, e, stage + " replace");
            }
            else
            {
                // guaranteed to contain only code labels, add to gatemap
            }

            return(e);
        }
예제 #16
0
 public Connection(IGate outputee, int outputPin, IGate inputee, int inputPin)
 {
     Outputee  = outputee;
     Inputee   = inputee;
     OutputPin = outputPin;
     InputPin  = inputPin;
 }
예제 #17
0
        public IGate AddGate(IGate g)
        {
            if (g.Type.IsFixed())
            {
                return(g);
            }
            else
            {
                var key = g.CacheKey;

                // try to find, including parents
                IGate r = Lookup(key);

                if (null == r)
                {
                    // add to cache
                    var gateid = "#" + _seed++;
                    g.Freeze(gateid);

                    _map[key] = r = g;
                    _list.Add(r);
                }

                return(r);
            }
        }
예제 #18
0
 public MembershipController(ISecurityUserReader securityUserReader, IGate gate, IAuthenticationService authenticationService, IDinnerReader dinnerReader)
 {
     _securityUserReader = securityUserReader;
     _gate = gate;
     _authenticationService = authenticationService;
     _dinnerReader = dinnerReader;
 }
예제 #19
0
        public IEnumerable <Transition> Match(IGate genter, IGate gleave)
        {
            var f1 = genter.GetProduct();
            var f2 = gleave.GetProduct();

            foreach (var f in f1.Factors)
            {
                // must exist ...
                var   t = GetTransitions(f.Variable).First();
                int[] indexes;
                if (f.Variable.Type.IsBoolean)
                {
                    indexes = new int[] { f.Inputs.First().IsInverted ? 0 : 1 };
                }
                else
                {
                    indexes = f.Inputs.Select(i => i.Address - i.Group).ToArray();
                }

                var q = t.PreStateIndexes.Intersect(indexes);

                if (!q.Any())
                {
                    // transition is not contained
                    yield break;
                }

                yield return(t);
            }
        }
예제 #20
0
        /// <summary>
        /// Are any of the current query parameters blocked by the gate critera?
        /// </summary>
        /// <param name="gate">gate</param>
        /// <returns>true if no blocked query parameters match the requests query parmeters</returns>
        private bool DoQueryParametersHaveAccess(IGate gate)
        {
            bool grantAccess = true;
            IDictionary <string, HashSet <string> > blockedQueryParameters = gate.BlockedQueryParameters;

            if (blockedQueryParameters != null && blockedQueryParameters.Count > 0)
            {
                IDictionary <string, HashSet <string> > requestsQueryParameters = Request?.QueryParameters;
                //if no params exist on the request, then we grant access by default.
                if (requestsQueryParameters == null || requestsQueryParameters.Count == 0)
                {
                    ULSLogging.LogTraceTag(0x23821053 /* tag_967bt */, Categories.GateSelection, Levels.Verbose,
                                           "Allowing access to gate '{0}' as the GatedRequest has no query parameters.",
                                           gate.Name ?? "<NULL>");
                    return(grantAccess);
                }

                //if any request query param matches a blocked query param, we should not grant access.
                foreach (string requestParameterName in requestsQueryParameters.Keys)
                {
                    if (blockedQueryParameters.ContainsKey(requestParameterName))
                    {
                        //if the wild card '*' is specified as a value for a blocked param, then we restrict access
                        if (blockedQueryParameters[requestParameterName].Contains(Gate.BlockedQueryParameterValueWildCard))
                        {
                            grantAccess = false;

                            ULSLogging.LogTraceTag(0x23821054 /* tag_967bu */, Categories.GateSelection, Levels.Verbose,
                                                   "Not allowing access to gate '{0}' with the query parameter(s) '{1}'='{2}' as all parameters with name '{3}' are blocked by the wildcard '*'.",
                                                   gate.Name ?? "<NULL>",
                                                   requestParameterName,
                                                   requestsQueryParameters[requestParameterName],
                                                   requestParameterName);

                            break;
                        }

                        //if there's corresponding parameters in the request and the list of blocked, we do not grant access
                        IEnumerable <string> intersection = blockedQueryParameters[requestParameterName]
                                                            .Intersect(requestsQueryParameters[requestParameterName], StringComparer.OrdinalIgnoreCase);

                        if (intersection.Count() > 0)
                        {
                            grantAccess = false;

                            ULSLogging.LogTraceTag(0x23821055 /* tag_967bv */, Categories.GateSelection, Levels.Verbose,
                                                   "Not allowing access to gate '{0}' as the query parameter(s) '{1}'='{2}' is in the set of blocked query parameters '{3}'.",
                                                   gate.Name ?? "<NULL>",
                                                   requestParameterName,
                                                   string.Join(",", intersection),
                                                   string.Join(", ", blockedQueryParameters.Select(parameter => string.Format("'{0}={1}'", parameter.Key, parameter.Value))));

                            break;
                        }
                    }
                }
            }

            return(grantAccess);
        }
예제 #21
0
파일: Log.cs 프로젝트: thomas13335/smg
 public static void TraceGuard(IGate gate1, IGate gate2, string p)
 {
     if (TraceFlags.ShowGuard)
     {
         TraceGateOp2(gate1, gate2, p);
     }
 }
예제 #22
0
        /// <summary>
        /// Is the ip address of the request part of the gate criteria
        /// </summary>
        /// <param name="gate">gate</param>
        /// <returns>true if the ip address of the request matches the gate criteria, false otherwise</returns>
        private bool DoesIPAddressHaveAccess(IGate gate)
        {
            bool             grantAccess = true;
            HashSet <string> ipRanges    = gate.KnownIPRanges;

            if (ipRanges != null)
            {
                grantAccess = false;

                foreach (string ipRange in ipRanges)
                {
                    if (Request != null && Request.IsPartOfKnownIPRange(KnownIpAddresses, ipRange))
                    {
                        grantAccess = true;
                        break;
                    }
                }

                if (!grantAccess)
                {
                    ULSLogging.LogTraceTag(0x23821058 /* tag_967by */, Categories.GateSelection, Levels.Verbose,
                                           "Not allowing access to gate '{0}' as the ip address of the request is not in the set of allowed known ip ranges '{1}'.",
                                           gate.Name ?? "<NULL>", string.Join(", ", ipRanges));
                }
            }

            return(grantAccess);
        }
예제 #23
0
 protected static void TraceSimplify(IGate a, IGate r, string format, params object[] args)
 {
     if (TraceFlags.ShowSimplify)
     {
         Log.TraceGateOp2(a, r, format, args);
     }
 }
예제 #24
0
파일: ANDGate.cs 프로젝트: thomas13335/smg
        public static IGate SimplifyMultiplicate(IGate g)
        {
            Debug.Assert(g.Type == GateType.AND);

            var or = new ORGate();
            or.AddInput(new TrueGate());

            IGate r = or;

            foreach (var e in g.GetInputs())
            {
                if (e.Type == GateType.OR)
                {
                    r = Gate.Multiply(r.GetInputs(), e.GetInputs());
                }
                else
                {
                    r = Gate.Multiply(r.GetInputs(), e);
                }
            }

            r = Gate.Simplify(r);

            TraceSimplify(g, r, "simplify AND");

            return r;
        }
예제 #25
0
        /// <summary>
        /// Is the gate applicable for the current context
        /// </summary>
        /// <param name="gate">gate to check</param>
        /// <returns>true if applicable, false otherwise</returns>
        public bool IsGateApplicable(IGate gate)
        {
            if (!Code.ValidateArgument(gate, nameof(gate), TaggingUtilities.ReserveTag(0x2382104a /* tag_967bk */)) ||
                !Code.ValidateNotNullOrWhiteSpaceArgument(gate.Name, nameof(gate.Name), TaggingUtilities.ReserveTag(0x2382104b /* tag_967bl */)))
            {
                return(false);
            }

            if (IsKnownApplicableGate(gate.Name))
            {
                return(true);
            }

            if (IsKnownBlockedGate(gate.Name))
            {
                return(false);
            }

            bool grantAccess = IsGateApplicableInternal(gate);

            if (grantAccess)
            {
                KnownApplicableGates.AddOrUpdate(gate.Name, _ => 0, (_, __) => 0);
            }
            else
            {
                KnownBlockedGates.AddOrUpdate(gate.Name, _ => 0, (_, __) => 0);
            }

            return(grantAccess);
        }
예제 #26
0
파일: TestGates.cs 프로젝트: stefc/evogate
 private void CheckGate(IGate gate, bool[] results)
 {
     this.CheckGate(gate, false, false, results[0]);
     this.CheckGate(gate, false, true,  results[1]);
     this.CheckGate(gate, true,  false, results[2]);
     this.CheckGate(gate, true,  true,  results[3]);
 }
예제 #27
0
 public DinnerController(IGate gate, IDinnerReader dinnerReader, IProfileReader profileReader, ISecurityUserReader securityUserReader)
 {
     _gate               = gate;
     _dinnerReader       = dinnerReader;
     _profileReader      = profileReader;
     _securityUserReader = securityUserReader;
 }
예제 #28
0
        public IGate NewGate()
        {
            IGate g = null;

            if (!Selected)
            {
                return(g);
            }

            Type          t      = nameToType[group.SelectedButton.ID];
            List <Iinput> inputs = Inputs[Containers[group.SelectedButton.ID]];

            int             length = 0;
            ConstructorInfo ctor   = null;

            foreach (var cs in t.GetConstructors())
            {
                if (length <= cs.GetParameters().Length)
                {
                    length = cs.GetParameters().Length;
                    ctor   = cs;
                }
            }

            object[] param = new object[inputs.Count];

            for (int i = 0; i < inputs.Count; i++)
            {
                param[i] = GetInputValue(inputs[i]);
            }

            g = ctor.Invoke(param) as IGate;

            return(g);
        }
 private void AssertGate(IGate expected,
                         IGate actual)
 {
     Console.WriteLine("Comparing Gate with id {0} and {1}...",
                       expected.Id,
                       actual.Id);
 }
예제 #30
0
        public static void Connect(IGate output, int outputPin, IGate input, int inputPin)
        {
            Connection connection = new Connection(output, outputPin, input, inputPin);

            output.SetOutputConnection(connection);
            input.SetInputConnection(connection);
        }
예제 #31
0
        private IGate Create(NetworkType itype)
        {
            IGate result = null;

            var asm = Assembly.GetExecutingAssembly().GetTypes();

            foreach (var type in asm)
            {
                //if (!type.IsClass || type.IsNotPublic) continue;

                Type[] interfaces = type.GetInterfaces();

                if (((IList)interfaces).Contains(typeof(IGate)))
                {
                    if (type.Name.Contains(itype.ToString()))
                    {
                        object obj = Activator.CreateInstance(type);
                        result = (IGate)obj;
                        break;
                    }
                }
            }

            return(result);
        }
예제 #32
0
        /// <summary>
        /// Schedules a gate for evaluation
        /// </summary>
        /// <param name="gate"></param>
        public void Schedule(IGate gate)
        {
            if (gate.Type.IsFixed())
            {
                return;
            }

            var g  = gate.Simplify();
            var id = GetCodeLabelIdentifier(CurrentStage, g);

            CodeLabel label;

            if (_labels.TryGetValue(id, out label))
            {
                Gate.TraceLabel(g, label.Gate, "schedule ...");
                label.Schedule();
            }
            else
            {
                Gate.TraceLabel(g, g, "schedule elements ...");
                foreach (var e in gate.SelectAll().OfType <LabelGate>())
                {
                    ((LabelGate)e).Schedule();
                }
            }
        }
예제 #33
0
 public static IEnumerable <Variable> GetVariables(this IGate gate)
 {
     return(gate
            .GetVariableConditions()
            .Select(e => e.Variable)
            .OrderBy(v => v.Index)
            .Distinct());
 }
예제 #34
0
        protected TransitionMonitor(TransitionSet tset, IGate pre, IGate post)
        {
            _transitions = tset;

            Name          = "internal";
            PreCondition  = pre;
            PostCondition = post;
        }
예제 #35
0
        protected TransitionMonitor(TransitionSet tset, IGate pre, IGate post)
        {
            _transitions = tset;

            Name = "internal";
            PreCondition = pre;
            PostCondition = post;
        }
예제 #36
0
        public Response DeleteById(int id)
        {
            IGate response = m_InformationFinder.Delete(id);

            return(response == null
                       ? HttpStatusCode.NotFound
                       : AsJson(response));
        }
예제 #37
0
파일: FullAdder.cs 프로젝트: stefc/evogate
 public FullAdder()
 {
     xor1=new XorGate();
     xor2=new XorGate();
     and1=new AndGate();
     and2=new AndGate();
     or=new OrGate();
 }
예제 #38
0
파일: Gate.cs 프로젝트: thomas13335/smg
        /// <summary>
        /// Composes two gates given the operator as a parameter.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>The resulting gate.</returns>
        public static IGate Compose(GateType type, IGate a, IGate b)
        {
            switch(type)
            {
                case GateType.OR:
                    return ComposeOR(a, b);

                case GateType.AND:
                    return ComposeAND(a, b);

                default:
                    throw new ArgumentException();
            }
        }
예제 #39
0
 public void Enable(Feature feature, IGate gate, object thing)
 {
     if (gate.DataType == typeof (bool) || gate.DataType == typeof (int))
     {
         Write(Key(feature, gate), thing.ToString().ToLower());
     }
     else if (gate.DataType == typeof (ISet<string>))
     {
         AddToSet(Key(feature, gate), thing.ToString());
     }
     else
     {
         UnsupportedDataType(gate);
     }
 }
예제 #40
0
        internal CodeLabel(GateConverter gc, int stage, int index, string name, IGate g)
            : this(index, name)
        {
            _gc = gc;
            _originalgate = _gate = g;

            Stage = stage;

            Debug.Assert(!(g is CodeLabel));

            // if (g is IVariableCondition)
            {
                _gate = new LabelGate(this);
            }
        }
예제 #41
0
        /// <summary>
        /// Converts a gate into a label gate.
        /// </summary>
        /// <param name="stage">The execution stage where the label is evaluated.</param>
        /// <param name="g">The gate to convert.</param>
        /// <returns>The converted gate.</returns>
        public IGate ConvertToGate(int stage, IGate g)
        {
            // simplify to get cached
            g = Gate.Simplify(g);

            if(g.Type.IsFixed())
            {
                //throw new Exception("cannot convert fixed gate.");
                return g;
            }

            if (!(g is LabelGate))
            {
                g = MakeCodeLabels(stage, g);
            }

            return g;
        }
예제 #42
0
 public void Disable(Feature feature, IGate gate, object thing)
 {
     if (gate.DataType == typeof(bool))
     {
         _database.KeyDelete(feature.Key);
     }
     else if (gate.DataType == typeof(int))
     {
         _database.HashSet(feature.Key, gate.Key, thing.ToString());
     }
     else if (gate.DataType == typeof(ISet<string>))
     {
         _database.HashDelete(feature.Key, ToField(gate, thing));
     }
     else
     {
         UnsupportedDataType(gate);
     }
 }
예제 #43
0
 public void Disable(Feature feature, IGate gate, object thing)
 {
     if (gate.DataType == typeof (bool))
     {
         Clear(feature);
     }
     else if (gate.DataType == typeof (int))
     {
         Write(Key(feature, gate), thing.ToString());
     }
     else if (gate.DataType == typeof (ISet<string>))
     {
         RemoveFromSet(Key(feature, gate), thing.ToString());
     }
     else
     {
         UnsupportedDataType(gate);
     }
 }
예제 #44
0
파일: ORGate.cs 프로젝트: thomas13335/smg
        private static void SimplifyConstants(ref IGate gate)
        {
            var inputs = gate.GetInputs();
            var list = new List<IGate>();

            foreach (var i in inputs)
            {
                if (i is TrueGate)
                {
                    // sum is constant => TRUE
                    gate = new TrueGate();
                    return;
                }
                else if (i is FalseGate)
                {
                    // remove any FALSE gates ...
                }
                else if (i.GetNestingLevel() > 1)
                {
                    var r = i.Simplify();
                    if (r.Type == GateType.OR)
                    {
                        list.AddRange(r.GetInputs());
                    }
                    else
                    {
                        list.Add(r);
                    }
                }
                else
                {
                    var r = i.Simplify();
                    list.Add(r);
                }
            }

            gate = ConsolidateList(list);
        }
예제 #45
0
        public TransitionCondition(ICondition lcond, ICondition rcond)
        {
            if (lcond.ContainsTransitions() || rcond.ContainsTransitions())
            {
                throw new CompilerException(ErrorCode.BadCondition,
                    "arguments to transition condition must not include transitions.");
            }

            // right hand must be a product
            var r = rcond.Decompose(ConditionMode.Static);
            if(r.Type == GateType.OR)
            {
                throw new CompilerException(ErrorCode.BadCondition,
                    "right side of a transition must be a product.");
            }

            _rgate = r;

            var rvclist = r.GetVariableConditions().ToArray();

            var l = lcond.Decompose(ConditionMode.Static);

            // split left side into terms ...
            IEnumerable<IGate> terms = new[] { l };
            if(l.Type == GateType.OR)
            {
                terms = l.GetInputs();
            }

            // construct the transition set from the left side terms and the right side product.
            var tset = BuildTransitionSet(terms, rvclist);

            Left = lcond;
            Right = rcond;
            Transitions = tset;
        }
예제 #46
0
 private IGate Convert(GateConverter gc, int stage, IGate c)
 {
     //return gc.ConvertToGate(stage, c);
     return c;
 }
예제 #47
0
 public HomeController(ISecurityUserReader securityUserReader, IGate gate, IShipReader shipReader)
 {
     _securityUserReader = securityUserReader;
     _gate = gate;
     _shipReader = shipReader;
 }
예제 #48
0
 public void ReplaceInput(int j, IGate input)
 {
     ValidateCanModify();
     _inputs[j] = input;
 }
예제 #49
0
        private IGate EvaluateRecurse(ICodeLabelEvaluator cg, IGate g)
        {
            if (g.Type == GateType.Input)
            {
                if (g is LabelGate)
                {
                    var lg = (LabelGate)g;
                    lg.Label.Evaluate(cg);
                }
            }
            else
            {
                var list = new List<IGate>();
                foreach (var i in g.GetInputs())
                {
                    var u = i;
                    var l = _gc.GetScheduledLabel(u);
                    if (null != l)
                    {
                        u = l;
                    }
                    else
                    {
                        u = EvaluateRecurse(cg, u);
                    }

                    list.Add(u);
                }

                g = SMG.Common.Gate.Compose(g.Type, list);
            }

            return g;
        }
예제 #50
0
 private static void UnsupportedDataType(IGate gate)
 {
     throw new NotSupportedException(string.Format("{0} is not supported by this adapter yet", gate.Name));
 }
예제 #51
0
 public virtual void AddInput(IGate gate)
 {
     ValidateCanModify();
     Debug.Assert(Type.IsLogical());
     _inputs.Add(gate);
 }
예제 #52
0
 /// <summary>
 /// Replaces variables conditions in a gate with the pre or post conditions.
 /// </summary>
 /// <param name="e">The gate to replace.</param>
 /// <param name="post">True if the post condition shall be evaluated, false otherwise.</param>
 /// <returns>The resulting gate.</returns>
 private IGate ReplaceVariableCondition(TransitionSet tset, IGate e, bool post)
 {
     return e.Replace(g => ReplaceVariableConditionHandler(tset, g, post));
 }
예제 #53
0
        /// <summary>
        /// Replaces composite state conditions with their elementary equivalents.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="post"></param>
        /// <returns></returns>
        private IGate ReplaceVariableConditionHandler(TransitionSet tset, IGate e, bool post)
        {
            IGate result = e;

            if (e is IVariableCondition)
            {
                var c = (IVariableCondition)e;
                var tlist = tset.GetTransitions(c.Variable);
                var count = tlist.Count();

                if(0 == count)
                {
                    // no transitions for this variable, keep
                }
                else if (count > 1)
                {
                    throw new CompilerException(ErrorCode.AmbigousPreCondition,
                        "multiple transitions for variable '" + c.Variable + "'.");
                }
                else
                {
                    // unique post state required
                    var t = tlist.First();
                    var stateindexes = post ? t.NewStateIndexes : t.PreStateIndexes;
                    if (stateindexes.Length != 1)
                    {
                        throw new CompilerException(ErrorCode.AmbigousPreCondition,
                            "ambigous variable condition.");
                    }

                    // replace with elementary
                    result = c.CreateElementaryCondition(stateindexes.First());
                }
            }

            // Gate.TraceDecompose(e, result, "var repl {0}", post);

            return result;
        }
예제 #54
0
 /// <summary>
 /// Replaces variable conditions refering to a transition set with constants.
 /// </summary>
 /// <param name="tset">The transition set.</param>
 /// <param name="gate">The gate to translate.</param>
 /// <param name="value"></param>
 /// <returns>The resulting modified gate.</returns>
 private IGate ReplaceTransitionVariables(TransitionSet tset, IGate gate, bool value)
 {
     return gate
         .Replace(g => ReplaceTransitionVariablesHandler(tset, g, value))
         .Simplify();
 }
예제 #55
0
        private IGate ReplaceTransitionVariablesHandler(TransitionSet tset, IGate q, bool value)
        {
            var result = q;

            if (result is IVariableCondition)
            {
                var vc = ((IVariableCondition)result);
                if (!tset.Contains(vc.Variable))
                {
                    result = Gate.Constant(value);
                }
            }

            return result;
        }
예제 #56
0
        /// <summary>
        /// Replaces all variables not found in a guard with one.
        /// </summary>
        /// <param name="gate"></param>
        /// <param name="monitor"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private IGate ReplaceNonGuardVariables(IGate gate, Guard monitor)
        {
            // get variables referenced in the condition
            var variables = monitor.PreCondition
                .SelectAll(e => e is IVariableCondition)
                .OfType<IVariableCondition>()
                .Select(u => u.Variable)
                .Distinct();

            var vset = new HashSet<Variable>(variables);

            // TraceDependencies("monitor variables: {0}", variables.ToSeparatorList());

            IGate r = gate
                .Replace(g =>
                {
                    if (g is IVariableCondition)
                    {
                        var vc = (IVariableCondition)g;
                        if (!vset.Contains(vc.Variable))
                        {
                            g = Gate.Constant(true);
                        }
                    }

                    return g;
                })
                .Simplify();

            return r;
        }
예제 #57
0
 private string Key(Feature feature, IGate gate)
 {
     return feature.Key + "/" + gate.Key;
 }
예제 #58
0
 public TaskRunnerController(IGate gate)
 {
     _gate = gate;
 }
예제 #59
0
 public MyEventsController(IDinnerReader dinnerReader, IGate gate)
 {
     _dinnerReader = dinnerReader;
     _gate = gate;
 }
예제 #60
0
 public ProfileController(IGate gate, IProfileReader profileReader)
 {
     _gate = gate;
     _profileReader = profileReader;
 }