Inheritance: GenericVariable
 public DifferenceConstraint(FloatVariable difference, FloatVariable a, FloatVariable b)
     : base(difference.CSP)
 {
     this.difference = difference;
     this.a = a;
     this.b = b;
 }
Beispiel #2
0
 public Vector3Variable(string name, CSP p, Interval x, Interval y, Interval z)
 {
     Name = name;
     X = new FloatVariable(name + ".X", p, x);
     Y = new FloatVariable(name + ".Y", p, y);
     Z = new FloatVariable(name + ".Z", p, z);
 }
 public DotProductConstraint(FloatVariable product, Vector3Variable a, Vector3Variable b)
     : base(product.CSP)
 {
     this.product = product;
     this.a = a;
     this.b = b;
 }
        public void EvenPowerNegativeATest()
        {
            var p = new CSP();
            var a = new FloatVariable("a", p, -3, 0);
            var power = a ^ 2;
            power.MustEqual(4f);

            p.TestConsistency();
            AssertUnique(a, -2f);
        }
        public void DifferenceTest()
        {
            var p = new CSP();
            var a = new FloatVariable("a", p, 0, 1);
            var b = new FloatVariable("b", p, 0, 1);
            var difference = a - b;
            a.MustEqual(0.5f);
            b.MustEqual(0.25f);

            p.TestConsistency();
            AssertUnique(difference, 0.25f);
        }
Beispiel #6
0
    // Start is called before the first frame update
    public override void InitializeAgent()
    {
        base.InitializeAgent();
        agentRb     = GetComponent <Rigidbody>();
        rayPer      = GetComponent <RayPerception3D>();
        HealthAgent = GetComponent <HealthAgent>();

        FloatVariable health = ScriptableObject.CreateInstance <FloatVariable>();

        health.InitialValue = InitialHealth;
        health.RuntimeValue = InitialHealth;
        HealthAgent.Health  = health;

        Academy = GameObject.FindObjectOfType <CibotAcademy>();
    }
Beispiel #7
0
        public override void Raise()
        {
            if (targetVariable is FloatVariable)
            {
                FloatVariable f = (FloatVariable)targetVariable;
                targetSlider.value = f.value;
                return;
            }

            if (targetVariable is IntVariable)
            {
                IntVariable i = (IntVariable)targetVariable;
                targetSlider.value = i.value;
            }
        }
Beispiel #8
0
        public void SemiconstrainedSumTest()
        {
            var p   = new CSP();
            var a   = new FloatVariable("a", p, 0, 1);
            var b   = new FloatVariable("b", p, 0, 1);
            var sum = a + b;

            sum.MustEqual(1);

            for (int i = 0; i < 1000; i++)
            {
                p.NewSolution();
                Assert.IsTrue(MathUtil.NearlyEqual(sum.UniqueValue, (a.UniqueValue + b.UniqueValue)));
            }
        }
    void Awake()
    {
        Damage    = ScriptableObject.Instantiate(Damage);
        Direction = ScriptableObject.Instantiate(Direction);
        Velocity  = ScriptableObject.Instantiate(Velocity);

        ProjectileMovement movement = GetComponent <ProjectileMovement>();

        movement.Direction.InstanceVariable = Direction;
        movement.Velocity.InstanceVariable  = Velocity;

        ProjectileDamage damage = GetComponent <ProjectileDamage>();

        damage.Damage.InstanceVariable = Damage;
    }
Beispiel #10
0
        /// <summary>
        /// Find the equivalence classes of variables in this model
        /// </summary>
        /// <param name="s">Boolean model against which to compute equivalence classes</param>
        private void FindEquivalenceClasses(Solution s)
        {
            // Alias vars that are equated in this model
            foreach (var p in Propositions)
            {
                if (p is VariableEquation e && s[e] && e.Lhs.IsDefinedInInternal(s) && e.Rhs.IsDefinedInInternal(s))
                {
                    FloatVariable.Equate(e.Lhs, e.Rhs);
                }
            }

            // We can now focus on just the representatives of each equivalence class of variables
            // and ignore the rest.
            representatives.Clear();
            representatives.AddRange(Variables.Where(v => v.IsDefinedInInternal(s) && (object)v == (object)v.Representative));
        }
Beispiel #11
0
        private void createWindow_Timers(Context context)
        {
            _bar_timers                  = new Bar(context);
            _bar_timers.Label            = "Timers (ms)";
            _bar_timers.Contained        = true;
            _bar_timers.Color            = Color.DarkRed;
            _bar_timers.Size             = new Size(250, 100);
            _bar_timers.ValueColumnWidth = 90;
            _bar_timers.Position         = new Point(10, 70);
            _bar_timers.RefreshRate      = 1;
            _bar_timers.Iconified        = true;

            _timer_1 = new FloatVariable(_bar_timers);
            _timer_2 = new FloatVariable(_bar_timers);
            _timer_3 = new FloatVariable(_bar_timers);
        }
    public void FloatReferenceTest_FloatVariableIsTheSameValue()
    {
        FloatVariable expected = ScriptableObject.CreateInstance <FloatVariable>();

        expected.SetValue(123f);

        FloatReference actual = new FloatReference();

        actual.UseConstant = false;
        actual.Variable    = ScriptableObject.CreateInstance <FloatVariable>();
        actual.Variable.SetValue(123f);

        Assert.IsFalse(actual.UseConstant);
        Assert.AreEqual(expected.Value, actual.Value);
        Assert.IsInstanceOf <FloatVariable>(actual.Variable);
    }
Beispiel #13
0
        public void InitController(ManagerBonuses managerBonuses, ManagerBalls managerBalls, IBonusControllerData data)
        {
            _bonuses = data.GetBonuses;
            _bonuses.Clear();
            _unusedBonuses = data.GetUnusedBonuses;
            _unusedBonuses.Clear();

            _borders        = data.GetBorders;
            _managerBonuses = managerBonuses;
            _managerBalls   = managerBalls;

            _isFaster    = data.GetIsFaster;
            _isSlowly    = data.GetIsSlowly;
            _isLongBoard = data.GetIsLongBoard;
            _activeTime  = data.GetActiveTime;
        }
Beispiel #14
0
        /// <inheritdoc />
        /// <summary>
        /// GUI display.
        /// </summary>
        public override void OnInspectorGUI()
        {
            variable = (FloatVariable)target;

            EditorGUI.BeginChangeCheck();
            {
                variable.Value = EditorGUILayout.FloatField("Value", variable.Value);

                variable.OnValueChanged = (GameEvent)EditorGUILayout.ObjectField("On value changed event",
                                                                                 variable.OnValueChanged, typeof(GameEvent), false);
            }
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(variable);
            }
        }
Beispiel #15
0
    //==========================================
    // FloatVariable (ScriptableObject) creator
    //==========================================
    private FloatVariable CreateNewFloatVariable()
    {
        string        path             = "Assets/FloatingBars/ScriptableObjects Example";
        FloatVariable newFloatVariable = CreateInstance("FloatVariable") as FloatVariable;

        newFloatVariable.name = floatVariableName;
        newFloatVariable.SetValue(floatVariableValue);

        string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + floatVariableName + ".asset");

        AssetDatabase.CreateAsset(newFloatVariable, assetPathAndName);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        return(newFloatVariable);
    }
        /// <summary>
        /// Read value from Mixer and load it into backing Variable.
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="variable"></param>
        private void LoadValueFromMixer(string propertyName,
                                        FloatVariable variable)
        {
            bool  propertyValid;
            float propertyValue;

            propertyValid = mainMixer.GetFloat(propertyName,
                                               out propertyValue);

            //validate
            Debug.AssertFormat(propertyValid, "[AudioMixerHelper] audioMixer {0}" +
                               " doesn't have an exposed property {1}",
                               mainMixer, propertyName);

            variable.Value = propertyValue;
        }
Beispiel #17
0
 public void ResetBuffs()
 {
     jumpForce          = _originalFloats[0];
     jumpEnhance        = _originalFloats[1];
     jumpEnhanceTimeMax = _originalFloats[2];
     horizontalMovement = _originalFloats[3];
     coyoteJump         = _originalFloats[4];
     downForce          = _originalFloats[5];
     speed         = _originalFloats[6];
     airSpeed      = _originalFloats[7];
     stumbleSmooth = _originalFloats[8];
     size          = _originalFloats[9];
     drag          = _originalFloats[10];
     //transform.GetComponent<Rigidbody2D>().drag = drag.Value;
     transform.localScale = new Vector3(1, 1, 1);
 }
Beispiel #18
0
        public void QuadraticTest()
        {
            var  p    = new CSP();
            var  a    = new FloatVariable("a", p, -100, 100);
            var  b    = new FloatVariable("b", p, -100, 100);
            var  quad = (a ^ 2) + b;
            bool fail = false;

            quad.NarrowTo(new Interval(10, 20), ref fail);

            for (int i = 0; i < 1000; i++)
            {
                p.NewSolution();
                Assert.IsTrue(MathUtil.NearlyEqual(quad.UniqueValue, (a.UniqueValue * a.UniqueValue + b.UniqueValue)));
            }
        }
    public void CreateModify()
    {
        if (intVarToModify != null)
        {
            c.variablesInt.Remove(intVarToModify);
            Destroy(intVarToModify.gameObject);
        }

        if (floatVarToModify != null)
        {
            c.variablesFloat.Remove(floatVarToModify);
            Destroy(floatVarToModify.gameObject);
        }

        if (boolVarToModify != null)
        {
            c.variablesBoolean.Remove(boolVarToModify);
            Destroy(boolVarToModify.gameObject);
        }

        switch (tipo)
        {
        case TipoVar.Int:
            IntVariable intVar = Instantiate(Manager.Instance.intVariablePrefab, new Vector3(999, 999, 999), Quaternion.identity);
            intVar.nombre     = nombreInput.text;
            intVar.proteccion = NivelDeProteccion;
            c.variablesInt.Add(intVar);
            p.AddVariable(indiceLinea, "int");
            break;

        case TipoVar.Float:
            FloatVariable floatVar = Instantiate(Manager.Instance.floatVariablePrefab, new Vector3(999, 999, 999), Quaternion.identity);
            floatVar.nombre     = nombreInput.text;
            floatVar.proteccion = NivelDeProteccion;
            c.variablesFloat.Add(floatVar);
            p.AddVariable(indiceLinea, "float");
            break;

        case TipoVar.Boolean:
            BoolVariable booleanVar = Instantiate(Manager.Instance.boolVariablePrefab, new Vector3(999, 999, 999), Quaternion.identity);
            booleanVar.nombre     = nombreInput.text;
            booleanVar.proteccion = NivelDeProteccion;
            c.variablesBoolean.Add(booleanVar);
            p.AddVariable(indiceLinea, "bool");
            break;
        }
    }
Beispiel #20
0
        /// <summary>
        /// Set an FloatVariable with the given tag.
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public void SetFloat(string tag, float value)
        {
            foreach (var variable in FloatVariables)
            {
                if (variable.Tag == tag)
                {
                    variable.Value = value;
                    return;
                }
            }
            //Not found
            var newVariable = new FloatVariable();

            newVariable.Tag   = tag;
            newVariable.Value = value;
            FloatVariables.Add(newVariable);
        }
Beispiel #21
0
        private void Update()
        {
            if (normalized == null)
            {
                normalized = new FloatVariable();
            }

            if (value == null)
            {
                value = new Vector3Variable();
            }

            value.runtimeValue.x = curveX.Evaluate(normalized);
            value.runtimeValue.y = curveY.Evaluate(normalized);
            value.runtimeValue.z = curveZ.Evaluate(normalized);

            transform.localScale = value.runtimeValue;
        }
        /// <summary>
        /// Raise true or false event stack based on the comparison of two number variables
        /// </summary>
        public override void Raise()
        {
            if (value1 == null || value2 == null)
            {
                Debug.Log("Number variable comparison doesn't have variables assigned! " + this.gameObject);
                return;
            }

            float v1 = 0;
            float v2 = 0;

            if (value1 is FloatVariable)
            {
                FloatVariable f = (FloatVariable)value1;
                v1 = f.value;
            }

            if (value1 is IntVariable)
            {
                IntVariable i = (IntVariable)value1;
                v1 = i.value;
            }

            if (value2 is FloatVariable)
            {
                FloatVariable f = (FloatVariable)value2;
                v2 = f.value;
            }

            if (value2 is IntVariable)
            {
                IntVariable i = (IntVariable)value2;
                v2 = i.value;
            }

            if (v1 < v2)
            {
                IfValue1IsLower.Invoke();
            }
            else
            {
                IfValue1IsHigher.Invoke();
            }
        }
    public void Load(string type, string proteccion, string nombre)
    {
        ProteccionVar p = ProteccionVar.Public;

        switch (proteccion)
        {
        case "Public":
            p = ProteccionVar.Public;
            break;

        case "Private":
            p = ProteccionVar.Public;
            break;

        case "Protected":
            p = ProteccionVar.Public;
            break;
        }

        switch (type)
        {
        case "int":
            IntVariable intVar = Instantiate(Manager.Instance.intVariablePrefab, new Vector3(999, 999, 999), Quaternion.identity);
            intVar.nombre     = nombre;
            intVar.proteccion = p;
            c.variablesInt.Add(intVar);
            break;

        case "float":
            FloatVariable floatVar = Instantiate(Manager.Instance.floatVariablePrefab, new Vector3(999, 999, 999), Quaternion.identity);
            floatVar.nombre     = nombre;
            floatVar.proteccion = p;
            c.variablesFloat.Add(floatVar);
            break;

        case "bool":
            BoolVariable booleanVar = Instantiate(Manager.Instance.boolVariablePrefab, new Vector3(999, 999, 999), Quaternion.identity);
            booleanVar.nombre     = nombre;
            booleanVar.proteccion = p;
            c.variablesBoolean.Add(booleanVar);
            break;
        }
    }
Beispiel #24
0
        public void UndefinedFloatVarTest()
        {
            var p    = new Problem("test");
            var dom  = new FloatDomain("signed unit", -1, 1);
            var prop = (Proposition)"prop";
            var x    = new FloatVariable("x", dom, prop, p);

            p.Assert(Not(prop));
            Solution s = null;

            for (int i = 0; i < 100; i++)
            {
                s = p.Solve();
                Console.WriteLine(s.Model);
                Assert.IsFalse(s[prop]);
                Assert.IsFalse(x.IsDefinedInInternal(s));
            }
            Console.WriteLine(x.Value(s));
        }
Beispiel #25
0
    public void OnCollided(GameObject thisGO, GameObject collidedWithGO)
    {
        GasBubbleBehaviour poopBubbleBehaviour = collidedWithGO.GetComponent <GasBubbleBehaviour>();

        if (poopBubbleBehaviour)
        {
            flightSpeedVariable = speedUpVariable;
            StartCoroutine(ResetSpeed(speedUpDuration));
            return;
        }

        FlyController controller = collidedWithGO.GetComponent <FlyController>();

        if (controller)
        {
            flightSpeedVariable = slowDownVariable;
            StartCoroutine(ResetSpeed(slowDownDuration));
        }
    }
Beispiel #26
0
        public void UndefinedFloatVarEquationHasNoEffectTest()
        {
            var p    = new Problem("test");
            var dom  = new FloatDomain("signed unit", -1, 1);
            var prop = (Proposition)"prop";
            var x    = new FloatVariable("x", dom, prop, p);
            var y    = (FloatVariable)dom.Instantiate("y");

            p.Assert(Not(prop));
            p.Assert(x == y);

            for (int i = 0; i < 100; i++)
            {
                var s = p.Solve();
                Assert.IsFalse(x.IsDefinedInInternal(s));
                Assert.IsTrue(y.IsDefinedInInternal(s));
                Assert.IsFalse(ReferenceEquals(x.Representative, y.Representative));
            }
        }
Beispiel #27
0
        public void GeneralSumConstraintTest()
        {
            var p    = new Problem(nameof(GeneralSumConstraintTest));
            var dom  = new FloatDomain("unit", -1, 1);
            var vars = new FloatVariable[10];

            for (int i = 0; i < vars.Length; i++)
            {
                vars[i] = (FloatVariable)dom.Instantiate("x" + i);
            }
            var sum = FloatVariable.Sum(vars);

            for (int i = 0; i < 100; i++)
            {
                var s = p.Solve();
                Console.WriteLine(s.Model);
                var realSum = vars.Select(v => v.Value(s)).Sum();
                Assert.IsTrue(Math.Abs(sum.Value(s) - realSum) < 0.00001f);
            }
        }
Beispiel #28
0
        public void AverageConstraintTest()
        {
            var p    = new Problem(nameof(AverageConstraintTest));
            var dom  = new FloatDomain("unit", -1, 1);
            var vars = new FloatVariable[10];

            for (int i = 0; i < vars.Length; i++)
            {
                vars[i] = (FloatVariable)dom.Instantiate("x" + i);
            }
            var average = FloatVariable.Average(vars);

            for (int i = 0; i < 100; i++)
            {
                var s = p.Solve();
                Console.WriteLine(s.Model);
                var avg = vars.Select(v => v.Value(s)).Average();
                Assert.IsTrue(Math.Abs(average.Value(s) - avg) < 0.00001f);
            }
        }
Beispiel #29
0
    //If a block is activated by the user, then this is not needed in the flowchart
    //Copies the variables in the list from the GM flowcharts to the activated flowchart
    public void CopyGameMasterToFlowchart()
    {
        gm = GameObject.Find("GameMaster").GetComponent <GameMaster>();
        Flowchart gmQuest = gm.GetQuestFlowchart();
        Flowchart target  = this.GetComponent <Flowchart>();

        Variable sourceVar = null;

        for (int i = 0; i < varNames.Length; i++)
        {
            sourceVar = gmQuest.GetVariable(varNames[i]);

            StringVariable tempstr = sourceVar as StringVariable;
            if (tempstr != null)
            {
                target.SetStringVariable(varNames[i], tempstr.Value);
                continue;
            }

            BooleanVariable tempBool = sourceVar as BooleanVariable;
            if (tempBool != null)
            {
                target.SetBooleanVariable(varNames[i], tempBool.Value);
                continue;
            }

            IntegerVariable tempInt = sourceVar as IntegerVariable;
            if (tempInt != null)
            {
                target.SetIntegerVariable(varNames[i], tempInt.Value);
                continue;
            }

            FloatVariable tempFloat = sourceVar as FloatVariable;
            if (tempFloat != null)
            {
                target.SetFloatVariable(varNames[i], tempFloat.Value);
                continue;
            }
        }
    }
Beispiel #30
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        FloatVariable variable = (FloatVariable)target;

        GUILayout.Space(20);
        GUILayout.BeginHorizontal();
        valueToSet = GUILayout.TextField(valueToSet, 50);
        if (GUILayout.Button("Set value"))
        {
            variable.SetValue(float.Parse(valueToSet));
            variable.Save();
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(20);

        if (variable.isPersistent)
        {
            if (GUILayout.Button("Load pref"))
            {
                variable.Load();
            }

            if (GUILayout.Button("Reset pref"))
            {
                variable.Clear();
            }

            if (GUILayout.Button("Set default"))
            {
                variable.SetValue(variable.DefaultValue);
                variable.Save();
            }

            if (GUILayout.Button("Reset all prefs"))
            {
                PlayerPrefs.DeleteAll();
            }
        }
    }
Beispiel #31
0
        public void EditorSetVariableData(FloatVariable global, FloatVariableInstanced instanced, float constant,
                                          AssignmentType type, IDTokenHolder tokenHolder)
        {
            _assignmentType = type;
            EditorSetTokenHolder(tokenHolder);

            switch (type)
            {
            case AssignmentType.Constant:
                _constantValue = constant;
                break;

            case AssignmentType.GlobalVariable:
                _globalVariable = global;
                break;

            case AssignmentType.PersonalVariable:
                _instancedVariable = instanced;
                break;
            }
        }
Beispiel #32
0
    private void Awake()
    {
        escolheFase   = Resources.Load <BoolVariable>("EscolheFase");
        faseEscolhida = Resources.Load <FloatVariable>("FaseEscolhida");

        if (resetaPlayerPrefs.Value == true)
        {
            escolheFase.Value       = true;
            faseEscolhida.Value     = 0;
            pularModoHistoria.Value = false;
            PlayerPrefs.DeleteAll();
            resetaPlayerPrefs.Value = false;
        }
        if (PlayerPrefs.GetInt("IsFirstTime") == 0)
        {
            isFirstTime = true;
        }
        else
        {
            isFirstTime = false;
        }
    }
Beispiel #33
0
        protected override void Start()
        {
            base.Start();
            team = StatAttribute.Create(1f, "Team");

            maxHealth = StatAttribute.Create(10f, "MaxHealth");
            health    = FloatVariable.Create(FloatConstant.Create(maxHealth.Value), FloatConstant.Create(0), maxHealth,
                                             AttributeType.Create("Health"));

            armor = StatAttribute.Create(10f, "Armor");

            speed           = StatAttribute.Create(3f, "Speed");
            sneakMultiplier = 0.7f;
            runMultiplier   = 2f;

            jumpPower = 450f;

            weight    = StatAttribute.Create(0, "Weight");
            maxWeight = StatAttribute.Create(0, "MaxWeight");

            slotCapacity = -1;
        }
    void Awake()
    {
        Direction         = ScriptableObject.Instantiate(Direction);
        Velocity          = ScriptableObject.Instantiate(Velocity);
        DesirableVelocity = ScriptableObject.Instantiate(DesirableVelocity);
        UnableToMove      = ScriptableObject.Instantiate(UnableToMove);

        Health     = ScriptableObject.Instantiate(Health);
        Resistence = ScriptableObject.Instantiate(Resistence);

        AttackDelay = ScriptableObject.Instantiate(AttackDelay);
        Target      = ScriptableObject.Instantiate(Target);

        EnemyMovement movement = GetComponent <EnemyMovement>();

        movement.Direction.InstanceVariable         = Direction;
        movement.Velocity.InstanceVariable          = Velocity;
        movement.DesirableVelocity.InstanceVariable = DesirableVelocity;
        movement.UnableToMove.InstanceVariable      = UnableToMove;
        movement.Target.InstanceVariable            = Target;

        EnemyHealth health = GetComponent <EnemyHealth>();

        health.Health.InstanceVariable      = Health;
        health.Resistence.InstanceVariable  = Resistence;
        health.Velocity.InstanceVariable    = Velocity;
        health.Target.InstanceVariable      = Target;
        health.AttackDelay.InstanceVariable = AttackDelay;

        EnemyAttack attack = GetComponent <EnemyAttack>();

        attack.Target.InstanceVariable      = Target;
        attack.AttackDelay.InstanceVariable = AttackDelay;

        EnemyTargetDetector target = GetComponentInChildren <EnemyTargetDetector>();

        target.Target.InstanceVariable = Target;
    }
Beispiel #35
0
    // Start is called before the first frame update
    public override void InitializeAgent()
    {
        base.InitializeAgent();
        agentRb        = GetComponent <Rigidbody>();
        rayPer         = GetComponent <RayPerception3D>();
        HealthAgent    = GetComponent <HealthAgent>();
        EnergyAgent    = GetComponent <EnergyAgent>();
        RaycastShooter = GetComponent <RaycastShooter>();

        PlayerHealthAgent = Player.GetComponent <HealthAgent>();

        FloatVariable health = ScriptableObject.CreateInstance <FloatVariable>();

        health.InitialValue = InitialHealth;
        health.RuntimeValue = InitialHealth;
        HealthAgent.Health  = health;

        FloatVariable energy = ScriptableObject.CreateInstance <FloatVariable>();

        energy.InitialValue    = InitialEnergy;
        energy.RuntimeValue    = InitialEnergy;
        EnergyAgent.EnergyPool = energy;
    }
        public void EqualityConstraintTest()
        {
            {
                var p = new CSP();
                var a = new FloatVariable("a", p, 0, 1);
                var b = new FloatVariable("b", p, 0, 1);
                var c = new FloatVariable("c", p);
                c.MustEqual(b);
                var sum = a + b;
                sum.MustEqual(1);

                for (int i = 0; i < 10; i++)
                {
                    p.NewSolution();
                    Assert.IsTrue(MathUtil.NearlyEqual(sum.UniqueValue, (a.UniqueValue + b.UniqueValue)));
                    Assert.AreEqual(c.Value, b.Value);
                }
            }

            {
                var p = new CSP();
                var a = new FloatVariable("a", p, 0, 1);
                var b = new FloatVariable("b", p, 0, 1);
                var c = new FloatVariable("c", p);
                b.MustEqual(c);
                var sum = a + b;
                sum.MustEqual(1);

                for (int i = 0; i < 10; i++)
                {
                    p.NewSolution();
                    Assert.IsTrue(MathUtil.NearlyEqual(sum.UniqueValue, (a.UniqueValue + b.UniqueValue)));
                    Assert.AreEqual(c.Value, b.Value);
                }
            }
        }
        public void UnconstrainedSumTest()
        {
            var p = new CSP();
            var a = new FloatVariable("a", p, 0, 1);
            var b = new FloatVariable("b", p, 0, 1);
            var sum = a + b;

            for (int i = 0; i < 1000; i++)
            {
                p.NewSolution();
                Assert.IsTrue(MathUtil.NearlyEqual(sum.UniqueValue, (a.UniqueValue + b.UniqueValue)));
            }
        }
Beispiel #38
0
 public Vector3Variable(FloatVariable x, FloatVariable y, FloatVariable z)
 {
     X = x;
     Y = y;
     Z = z;
 }
        public void QuotientTest()
        {
            var p = new CSP();
            var a = new FloatVariable("a", p, 0, 1);
            var b = new FloatVariable("b", p, 0, 1);
            var quotient = a / b;
            a.MustEqual(0.5f);
            b.MustEqual(0.5f);

            p.TestConsistency();
            AssertUnique(quotient, 1);
        }
Beispiel #40
0
 public void MustBeParallel(Vector3Variable v)
 {
     var coefficient = new FloatVariable("parallelCoefficient", CSP, Interval.AllValues);
     this.MustEqual(coefficient * v);
 }
 static void AssertUnique(FloatVariable v, double value)
 {
     Assert.IsTrue(v.IsUnique);
     Assert.AreEqual(value, v.UniqueValue);
 }
 public MagnitudeConstraint(FloatVariable magnitude, Vector3Variable vector)
     : base(magnitude.CSP)
 {
     this.magnitude = magnitude;
     this.vector = vector;
 }
        public void QuadraticTest()
        {
            var p = new CSP();
            var a = new FloatVariable("a", p, -100, 100);
            var b = new FloatVariable("b", p, -100, 100);
            var quad = (a^2) + b;
            bool fail = false;
            quad.NarrowTo(new Interval(10, 20), ref fail);

            for (int i = 0; i < 1000; i++)
            {
                p.NewSolution();
                Assert.IsTrue(MathUtil.NearlyEqual(quad.UniqueValue, (a.UniqueValue * a.UniqueValue + b.UniqueValue)));
            }
        }
 public override void CanonicalizeVariables()
 {
     difference = RegisterCanonical<FloatVariable, Interval>(difference);
     a = RegisterCanonical<FloatVariable, Interval>(a);
     b = RegisterCanonical<FloatVariable, Interval>(b);
 }
 public override void CanonicalizeVariables()
 {
     sum = RegisterCanonical<FloatVariable, Interval>(sum);
     a = RegisterCanonical<FloatVariable, Interval>(a);
     b = RegisterCanonical<FloatVariable, Interval>(b);
 }
 public PowerConstraint(FloatVariable power, FloatVariable a, uint exponent)
     : base(power.CSP)
 {
     this.power = power;
     this.a = a;
     this.exponent = exponent;
 }
 public ProductConstraint(FloatVariable product, FloatVariable a, FloatVariable b)
     : base(product.CSP)
 {
     this.product = product;
     this.a = a;
     this.b = b;
 }
 public ProductConstantConstraint(FloatVariable product, FloatVariable a, double k)
     : base(product.CSP)
 {
     this.product = product;
     this.a = a;
     this.k = k;
 }
        public void SumTest()
        {
            var p = new CSP();
            var a = new FloatVariable("a", p, 0, 1);
            var b = new FloatVariable("b", p, 0, 1);
            var sum = a + b;
            a.MustEqual(0.5f);
            b.MustEqual(0.25f);

            p.TestConsistency();
            AssertUnique(sum, 0.75f);
        }
        public void ProductTest()
        {
            var p = new CSP();
            var a = new FloatVariable("a", p, 0, 1);
            var b = new FloatVariable("b", p, 0, 1);
            var product = a * b;
            a.MustEqual(0.5f);
            b.MustEqual(0.5f);

            p.TestConsistency();
            AssertUnique(product, 0.25f);
        }
 public SumConstraint(FloatVariable sum, FloatVariable a, FloatVariable b)
     : base(sum.CSP)
 {
     this.sum = sum;
     this.a = a;
     this.b = b;
 }
 public override void CanonicalizeVariables()
 {
     quotient = RegisterCanonical<FloatVariable, Interval>(quotient);
     a = RegisterCanonical<FloatVariable, Interval>(a);
     b = RegisterCanonical<FloatVariable, Interval>(b);
 }
 public override void CanonicalizeVariables()
 {
     this.magnitude = RegisterCanonical<FloatVariable, Interval>(this.magnitude);
     this.vector.CanonicalizeAndRegisterConstraint(this);
 }
 public override void CanonicalizeVariables()
 {
     power = RegisterCanonical<FloatVariable, Interval>(power);
     a = RegisterCanonical<FloatVariable, Interval>(a);
 }
 public override void CanonicalizeVariables()
 {
     product = RegisterCanonical<FloatVariable, Interval>(product);
     a.CanonicalizeAndRegisterConstraint(this);
     b.CanonicalizeAndRegisterConstraint(this);
 }
Beispiel #56
0
 public static FloatVariable Dot(Vector3Variable a, Vector3Variable b)
 {
     return a.X.CSP.Memoize(
         "dot",
         () =>
             {
                 var product = new FloatVariable(
                     string.Format("{0} dot {1}", a.Name, b.Name),
                     a.X.CSP,
                     a.X.Value * b.X.Value + a.Y.Value * b.Y.Value + a.Z.Value * b.Z.Value);
                 // ReSharper disable ObjectCreationAsStatement
                 new DotProductConstraint(product, a, b);
                 // ReSharper restore ObjectCreationAsStatement
                 return product;
             },
         a,
         b);
 }
Beispiel #57
0
 private void MakeFloatVariable(CSP csp)
 {
     this.mFloatVariable = new FloatVariable(VariableName, csp, new Interval(Min, Max));
 }
Beispiel #58
0
 /// <summary>
 /// Update component variables to point at their canonical variables
 /// </summary>
 public void CanonicalizeAndRegisterConstraint(Constraint c)
 {
     X = c.RegisterCanonical<FloatVariable, Interval>(X);
     Y = c.RegisterCanonical<FloatVariable, Interval>(Y);
     Z = c.RegisterCanonical<FloatVariable, Interval>(Z);
 }
 public QuotientConstraint(FloatVariable quotient, FloatVariable a, FloatVariable b)
     : base(quotient.CSP)
 {
     this.quotient = quotient;
     this.a = a;
     this.b = b;
 }
 public override void CanonicalizeVariables()
 {
     product = RegisterCanonical<FloatVariable, Interval>(product);
     a = RegisterCanonical<FloatVariable, Interval>(a);
     b = RegisterCanonical<FloatVariable, Interval>(b);
 }