Example #1
0
 public virtual void VisitVar(IVar var, Compiler compiler)
 {
     if (!loopVariables.Contains(var))
     {
         throw new ArgumentException($"An input of the graph was not provided and not given a value: {var.Name}");
     }
 }
Example #2
0
        public VarGetter(INodeGraph bp, IVar variable) : base(bp)
        {
            Assert.IsNotNull(variable);
            m_Var = variable;

            AddBaseComponet();
        }
 public PuzzleEditorSquareContentsCell(PuzzleEditor parent, Vector2D position)
     : base(SquareToBool(parent.editorGrid.Squares[position]))
 {
     this.parent   = parent;
     this.contents = parent.editorGrid.Contents[position];
     this.position = position;
 }
Example #4
0
            public VarDefaultEditor(IVar @var)
            {
                m_Var      = @var;
                m_EditName = m_Var.Name;

                m_Var.OnSetName += new NameEvent(SetNameProc);
            }
 public PlayablePuzzleSquareContentsCell(PlayablePuzzle parent, IVar <Square> contents, Vector2D position)
     : base(contents.Value)
 {
     this.parent   = parent;
     this.contents = contents;
     this.position = position;
 }
 public override void VisitVar(IVar var, Compiler compiler)
 {
     // nothing: a variable not yet declared is not an error
     // It indicates that this variable belongs to the loop
     // (it was not declared before processing the loop)
     // and thus that expressions using this variable won't be moved out of the loop
     // e.g. see VisitUnaryElementWise: if (!Compiler.Scope.Contains(unary.x)) return true
 }
Example #7
0
        public void AddVar(IVar avar)
        {
            if (ContainsVar(avar.Key))
            {
                throw new VarAlreadyExistsException(avar.Key);
            }

            vars.Add(avar);
            RebuildIndex();
        }
 internal static string VariableDefinition(IVar variable)
 {
     if (variable != null)
     {
         return(variable.Name + " : " + variable.Type + ";\n");
     }
     else
     {
         return(null);
     }
 }
        public void VisitVar(IVar var, Tensor <float> data)
        {
            var other = data as Tensor <float> .Var;

            if (other == null)
            {
                Arent();
            }
            else
            {
                Eq(var.Name, other.Name);
            }
        }
        private VarInfo MakeVarInfo(IVar avar)
        {
            if (avar is IntVar intVar)
            {
                return(new VarInfo
                {
                    Type = VarType.IntVar,
                    Key = intVar.Key,
                    NameAssetKey = intVar.NameAssetKey,
                    Value = intVar.Value,
                    Parameters = new object[] { intVar.MinValue, intVar.MaxValue }
                });
            }

            if (avar is DoubleVar doubleVar)
            {
                return(new VarInfo
                {
                    Type = VarType.DoubleVar,
                    Key = doubleVar.Key,
                    NameAssetKey = doubleVar.NameAssetKey,
                    Value = doubleVar.Value,
                    Parameters = new object[] { doubleVar.MinValue, doubleVar.MaxValue }
                });
            }

            if (avar is BoolVar boolVar)
            {
                return(new VarInfo
                {
                    Type = VarType.BoolVar,
                    Key = boolVar.Key,
                    NameAssetKey = boolVar.NameAssetKey,
                    Value = boolVar.Value
                });
            }

            if (avar is StringVar stringVar)
            {
                return(new VarInfo
                {
                    Type = VarType.StringVar,
                    Key = stringVar.Key,
                    NameAssetKey = stringVar.NameAssetKey,
                    Value = stringVar.Value,
                    Parameters = new object[] { stringVar.MaxLength }
                });
            }

            throw new ArgumentException("Unsupported var type", nameof(avar));
        }
Example #11
0
        public IVar getCustomVariable(string variableName)
        {
            IVar result = null;

            foreach (var variable in this.CustomVars)
            {
                if (variable.Name == variableName)
                {
                    result = variable;
                    break;
                }
            }
            return(result);
        }
Example #12
0
        private static int getTotalAmountOfDivisionVar(IVar variable, List <KpCore.Rule> divisionRules, List <InstanceBlueprint> result)
        {
            int    totalAmount   = 0;
            bool   isFirstParent = true;
            string typeName      = "";

            foreach (InstanceBlueprint item in result)
            {
                typeName = item.Type.Name;
                int childValue = 0;
                int leftValue  = 0;
                foreach (var divisionRule in divisionRules)
                {
                    DivisionRule divRule = (DivisionRule)divisionRule;
                    if (divRule.Rhs.Contains(item))
                    {
                        Multiset leftOfRule = divRule.Lhs;
                        foreach (var leftObj in leftOfRule.Objects)
                        {
                            if (leftObj.Equals(variable.Name))
                            {
                                if (isFirstParent)
                                {
                                    totalAmount   = leftOfRule[leftObj];
                                    isFirstParent = false;
                                }
                                leftValue = leftOfRule[leftObj];
                            }
                        }
                    }
                }
                Multiset ms = item.Multiset;
                foreach (var obj in ms.Objects)
                {
                    if (obj.Equals(variable.Name))
                    {
                        childValue = ms[obj];
                    }
                }

                totalAmount = totalAmount - leftValue + childValue;
            }
            //update max value.
            if (variable.Type is BoundInt)
            {
                (variable.Type as BoundInt).UpperBound = Math.Max((variable.Type as BoundInt).UpperBound, totalAmount);
            }

            return(totalAmount);
        }
Example #13
0
        /// <summary>
        /// if variable parametrized then returns the init s with parameter,
        /// otherwise init s with given default value will be 0.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="variable"></param>
        /// <returns></returns>
        public static string setOrUpdateInit(Module module, IVar variable)
        {
            string initialValue = "0";

            //is it initialized with parameter
            foreach (var parameter in module.Parameters)
            {
                if (variable.Name == parameter.Name)
                {
                    initialValue = parameter.ParamName;
                    break;
                }
            }
            return(initialValue);
        }
Example #14
0
 private static void assignStatusAndSyncToAVariable(Module module, IVar variable)
 {
     if (variable is Variable)
     {
         CaseLine caseLine      = new CaseLine();
         Variable var           = (Variable)variable;
         String   exchangeState = SynchStates.EXCHANGE;
         //For Copy variables inside module
         if (var.Origin == VariableOrigin.Copy || var.Origin == VariableOrigin.CopyOfCommVar)
         {
             Expression result = new Expression("0");
             caseLine.Rule.Condition = getStatusAndSynchCondition(module, exchangeState);
             caseLine.Result         = result;
             var.Next.CaseStatement.CaseLines.Add(caseLine);
         }
         //For Original variables inside module
         else if (var.Origin == VariableOrigin.Original && var.Behaviour != VariableBehaviour.COMMUNICATION)
         {
             //if it has copy var, then add  var + var_cp
             if (module.isVariableExist(SMVPreFix.getCopyName(var)))
             {
                 OperExp result = new OperExp();
                 result.Exp        = variable.Name;
                 result.Oper.Value = MathOper.ADD;
                 //if variable is a division variable, then it has go to main part, like comm vars, so it will be instanced.
                 if (var.Behaviour == VariableBehaviour.DIVISION)
                 {
                     result.Result = new InstancedExp(variable.Name + SMVPreFix.COPY);
                 }
                 else
                 {
                     result.Result = new Expression(variable.Name + SMVPreFix.COPY);
                 }
                 ICondition boundCondition = getBoundCondition(var, result);
                 caseLine.Rule.Condition = new CompoundBoolExpression(getStatusAndSynchCondition(module, exchangeState), BinaryOperator.AND, boundCondition);
                 caseLine.Result         = result;
                 var.Next.CaseStatement.CaseLines.Add(caseLine);
             }
         }
         //for communication variables, goes into main module.
         else if (var.Origin == VariableOrigin.OriginalCommVar && var.Behaviour == VariableBehaviour.COMMUNICATION)
         {
             CaseLine commCaseLine = assignStatusAndSyncToACommVariable(module, var);
             var.Next.CaseStatement.CaseLines.Add(commCaseLine);
         }
     }
 }
 internal static string InitVariable(IVar variable)
 {
     if (variable is NoNextVar)
     {
         return(variable.Name + " := " + (variable as NoNextVar).Init + ";\n");
     }
     else if (variable is Variable)
     {
         return("init (" + variable.Name + ") := " + (variable as Variable).Init + ";\n");
     }
     else if (variable is NonDeterVar)
     {
         return(variable.Name + " := " + (variable as NonDeterVar).NonDetCase + ";\n");
     }
     else
     {
         return("Couldn't return init for " + variable.Name + " at " + MethodBase.GetCurrentMethod().Name + ";\n");;
     }
 }
Example #16
0
        private static CaseLine trueCaseLine(IVar variable)
        {
            CaseLine caseLine = new CaseLine();

            NuSMV.Rule rule = new NuSMV.Rule();
            rule.Condition = new TruthValue(Truth.TRUE);
            IExp exp = null;

            if (variable.Behaviour == VariableBehaviour.COMMUNICATION || variable.Behaviour == VariableBehaviour.DIVISION)
            {
                exp = new InstancedExp(variable.Name);
            }
            else
            {
                exp = new Expression(variable.Name);
            }
            caseLine.Rule   = rule;
            caseLine.Result = exp;
            return(caseLine);
        }
Example #17
0
        /// <summary>
        /// if variable parametrized then returns the init s with parameter,
        /// otherwise init s with given default value.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="variable"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static string setOrUpdateInit(Module module, IVar variable, string defaultValue)
        {
            string initialValue = "";

            //is it initialized with parameter
            foreach (var parameter in module.Parameters)
            {
                if (variable.Name == parameter.Name)
                {
                    initialValue = parameter.ParamName;
                    break;
                }
            }
            //if it is not parametrized.
            if (String.IsNullOrWhiteSpace(initialValue))
            {
                initialValue = defaultValue;
            }
            return(initialValue);
        }
 internal static string VariableNext(IVar variable)
 {
     if (variable is NoNextVar)
     {
         return("");
     }
     else if (variable is Variable)
     {
         if (variable.Name == CustomVariables.SYNCH)
         {
             return("next (" + variable.Name + ") := " + (variable as Variable).Next.CaseStatement.ToString().Replace("&", "\n\t&") + ";\n");
         }
         return("next (" + variable.Name + ") := " + (variable as Variable).Next + ";\n");
     }
     else if (variable is NonDeterVar)
     {
         return("");
     }
     else
     {
         return("Couldn't return init for " + variable.Name + " at " + MethodBase.GetCurrentMethod().Name + ";\n");;
     }
 }
Example #19
0
        /// <summary>
        /// Adds sequence of execution strategy, such as, choice
        /// </summary>
        /// <param name="module"></param>
        /// <param name="strategyIndex"></param>
        /// <returns></returns>
        internal static ICondition getSequenceCondition(Module module, int strategyIndex, int ruleID)
        {
            BoolExp boolExpression = new BoolExp();

            Strategy ex = module.ExecutionStrategies.ElementAt(strategyIndex);

            if (ex.Type == StrategyTypes.CHOICE)
            {
                IVar sequence = ex.CustomVars.Find(variable => variable.Name == (CustomVariables.CHOICE + strategyIndex));
                boolExpression.Left = new Expression(sequence.Name);
                boolExpression.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                boolExpression.Right = new Expression(ruleID.ToString());
            }
            else if (ex.Type == StrategyTypes.SEQUENCE)
            {
                IVar sequence = ex.CustomVars.Find(variable => variable.Name == (CustomVariables.SEQUENCE + strategyIndex));
                boolExpression.Left = new Expression(sequence.Name);
                boolExpression.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                boolExpression.Right = new Expression(ruleID.ToString());
            }
            else if (ex.Type == StrategyTypes.ARBITRARY)
            {
                IVar sequence = ex.CustomVars.Find(variable => variable.Name == (CustomVariables.ARBITRARY + strategyIndex));
                boolExpression.Left = new Expression(sequence.Name);
                boolExpression.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                boolExpression.Right = new Expression(ruleID.ToString());
            }
            else if (ex.Type == StrategyTypes.MAX)
            {
                IVar sequence = ex.CustomVars.Find(variable => variable.Name == (CustomVariables.MAX + strategyIndex));
                boolExpression.Left = new Expression(sequence.Name);
                boolExpression.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                boolExpression.Right = new Expression(ruleID.ToString());
            }
            return(boolExpression);
        }
 public PlayablePuzzleSquare(PlayablePuzzle parent, IVar <Square> contents, Vector2D position)
 {
     this.Contents = new PlayablePuzzleSquareContentsCell(parent, contents, position);
     this.Position = position;
 }
Example #21
0
 public void OnChanged(IVar v)
 {
     _Watcher(v);
 }
 internal SetExpression(Cons args, Env env, Interpreter interpreter, Loc loc)
 {
     this.loc = loc;
     this.interpreter = interpreter;
     Int32 len = Cons.Length(args);
     if (len != 2)
         throw new Exception("Wrong number of args for set");
     var = (IVar)interpreter.analyze(args.first, env, loc);
     val = interpreter.analyze(Cons.Second(args), env, loc);
 }
Example #23
0
 public Var(IVar <T> value)// : this()
 {
     this.value = value;
 }
Example #24
0
 public static Func <T1, T2> Function <T1, T2>(IVar <T1> input, IExpr <T2> output,
                                               OrderedDictionary /*<TensorExpr.Shared, TensorExpr>*/ updates = null, IDictionary givens = null, string name = null)
 {
     return(FunctionBinder.Function(input, output, updates, givens, name: name));
 }
Example #25
0
 public bool IsValid(IVar <T> v, T newVal)
 {
     return(Checker(v, newVal));
 }
Example #26
0
 public void OnVarChange(IVar theVar)
 {
     // ...
 }
Example #27
0
 public void OnVarChage(IVar variable)
 {
     m_Var = variable;
     NotifyVarChange();
 }
        internal static string CommunicationVariableNext(NuSMV.Module module, Instance instance, IVar var)
        {
            if (var is Variable)
            {
                string   op       = "case\n";
                Variable variable = (Variable)var;
                Next     next     = variable.Next;

                foreach (var caseLine in next.CaseStatement.CaseLines)
                {
                    if ((caseLine.Rule is CommunicationRule))
                    {
                        op += caseLine.ToString().Replace(SMVKeys.SELF, instance.Name);
                    }
                }
                foreach (var caseLine in next.CaseStatement.CaseLines)
                {
                    // CaseLine newcaseLine = new CaseLine();
                    if (!(caseLine.Rule is CommunicationRule))
                    {
                        string temp = "";
                        temp += insertInstanceName(caseLine.Rule.Condition, instance);
                        temp += " : ";
                        if (caseLine.Result is InstancedExp)
                        {
                            if (!caseLine.Result.ToString().Contains(instance.Name))
                            {
                                temp += instance.Name + "." + caseLine.Result;
                            }
                            else
                            {
                                temp += caseLine.Result;
                            }
                        }
                        else if (caseLine.Result is Expression)
                        {
                            temp += caseLine.Result;
                        }
                        temp += ";\n";
                        op   += temp;
                    }
                }
                op += "esac;\n";
                return("next (" + instance.Name + "." + var.Name + ") := " + op);
            }
            else
            {
                return("Couldn't generate next for " + var.Name + " at " + MethodBase.GetCurrentMethod().Name + ";\n");;
            }
        }
Example #29
0
 public void OnChanged(IVar <T> v, T oldValue)
 {
     Watcher(v, oldValue);
 }
 public bool IsValid(IVar <T> v, T newVal)
 {
     return(IsValid(newVal));
 }
Example #31
0
File: IVar.cs Project: silky/Hopac
 public IVarFill(IVar <T> iv, T x)
 {
     this.IV = iv;
     this.X  = x;
 }