Inheritance: NumVariable
Exemple #1
0
    public void CreateVariablesToTrackEnemies()
    {
        string[] paths = AssetDatabase.FindAssets("t:" + typeof(EnemyData).Name);
        for (int i = 0; i < paths.Length; i++)
        {
            paths[i] = AssetDatabase.GUIDToAssetPath(paths[i]);
        }

        List <EnemyData> enemies = paths.Select(AssetDatabase.LoadAssetAtPath <EnemyData>).ToList();

        foreach (var enemyData in enemies)
        {
            string variableTitle = $"{enemyData.DisplayName}sKilled";
            if (AssetDatabase.FindAssets(variableTitle).Length != 0)
            {
                continue;
            }
            IntVariable variable = ScriptableObject.CreateInstance <IntVariable>();
            variable.Value = 0;

            AssetDatabase.CreateAsset(variable, $"Assets/Data/StatVariables/Killed/{variableTitle}.asset");
            EnemyKillCount.Add(new EnemyCounter()
            {
                Enemy = enemyData,
                Count = variable
            });
        }
    }
Exemple #2
0
            //STASH / RETRIEVE always operate on the global execution context - all
            //variables have visibility to everyone in the program flow.  Note that
            //there is no way to know if any given identifier is currently holding a value
            //set by another component or is just uninitialized.  Such is the power
            //of intercal!  Perhaps every module should track in its metadata a listing
            //of the identifiers used in that component?  These would take the form
            //of assembly attributes?
            Variable GetVariable(string varname)
            {
                Variable retval = null;

                if (varname[0] == '.' || varname[0] == ':')
                {
                    if (!Variables.TryGetValue(varname, out retval))
                    {
                        Variable v = new IntVariable(this, varname);
                        Variables[varname] = v;
                        retval             = v;
                    }
                }
                else if (varname[0] == ',' || varname[0] == ';')
                {
                    if (!Variables.TryGetValue(varname, out retval))
                    {
                        Variable v = new ArrayVariable(this, varname);
                        Variables[varname] = v;
                        retval             = v;
                    }
                }
                else
                {
                    Lib.Fail(Messages.E241);
                }

                return(retval);
            }
Exemple #3
0
    public void CreateVariablesToTrackItems()
    {
        string[] paths = AssetDatabase.FindAssets("t:" + typeof(Item).Name);
        for (int i = 0; i < paths.Length; i++)
        {
            paths[i] = AssetDatabase.GUIDToAssetPath(paths[i]);
        }

        List <Item> items = paths.Select(AssetDatabase.LoadAssetAtPath <Item>).ToList();

        foreach (var item in items)
        {
            string variableTitle = $"{item.Name}sCollected";
            if (AssetDatabase.FindAssets(variableTitle).Length != 0)
            {
                continue;
            }
            IntVariable variable = ScriptableObject.CreateInstance <IntVariable>();
            variable.Value = 0;

            AssetDatabase.CreateAsset(variable, $"Assets/Data/StatVariables/Collected/{variableTitle}.asset");
            ItemObtainedCount.Add(new ItemCounter()
            {
                Item  = item,
                Count = variable
            });
        }
    }
 public void Construct(SignalBus signalBus,
                       PlayerData playerData)
 {
     _signalBus     = signalBus;
     _creepsCounter = playerData.CurrentCreepsAlive.Variable;
     _waveCounter   = playerData.CurrentWave.Variable;
 }
Exemple #5
0
        internal static void pp()
        {
            Network net = new Network();
            // number of materials
            int m = 3;

            // limit of each material
            int[] limit = new int[] { 1650, 1400, 1800 };
            // number of products
            int n = 2;

            // profit of each product
            int[] p = new int[] { 5, 4 };
            // amount of materials required to make each product
            int[][] a = new int[][] { new int[] { 15, 10, 9 }, new int[] { 11, 14, 20 } };

            // initialize variables for products
            IntVariable[] x = new IntVariable[n];
            for (int j = 0; j < n; j++)
            {
                x[j] = new IntVariable(net);
                x[j].Ge(0);
            }
            // generate constraits of limiting materials
            for (int i = 0; i < m; i++)
            {
                IntVariable sum = new IntVariable(net, 0);
                for (int j = 0; j < n; j++)
                {
                    sum = sum.Add(x[j].Multiply(a[j][i]));
                }
                sum.Le(limit[i]);
            }
            // total profit
            IntVariable profit = new IntVariable(net, 0);

            for (int j = 0; j < n; j++)
            {
                profit = profit.Add(x[j].Multiply(p[j]));
            }
            // maximize the total profit
            net.Objective = profit;
            // iteratively find a better solution until the optimal solution is found
            Solver solver = new DefaultSolver(net, Solver.Maximize | Solver.Better);

            for (solver.Start(); solver.WaitNext(); solver.Resume())
            {
                Solution solution = solver.Solution;
                Console.WriteLine(solver.GetCount());
                Console.Out.WriteLine("Profit = " + solution.GetIntValue(profit));
                for (int j = 0; j < n; j++)
                {
                    Console.Out.WriteLine("x[" + j + "]=" + solution.GetIntValue(x[j]));
                }
                Console.Out.WriteLine();
            }

            solver.Stop();
            Console.ReadLine();
        }
Exemple #6
0
        /// <summary>
        /// Invoke the true or false event stack based on a comparison of your targetVariable and a fixed number
        /// The comparison only runs when the Raise() is called, it's not monitored in Update or etc.
        /// </summary>
        public override void Raise()
        {
            if (targetVariable == null)
            {
                Debug.Log("No number variable assigned in a fixed number to numberVariable comparison! " + this.gameObject.name);
                return;
            }

            if (targetVariable is FloatVariable)
            {
                FloatVariable f = (FloatVariable)targetVariable;
                if (f.value < fixedNumber)
                {
                    IfVariableIsLower.Invoke();
                }
                else
                {
                    IfVariableIsHigher.Invoke();
                }
            }

            if (targetVariable is IntVariable)
            {
                IntVariable i = (IntVariable)targetVariable;
                int         v = Mathf.RoundToInt(fixedNumber);
                if (i.value < v)
                {
                    IfVariableIsLower.Invoke();
                }
                else
                {
                    IfVariableIsHigher.Invoke();
                }
            }
        }
Exemple #7
0
    public static void Main(String[] args)
    {
        Network     net = new Network();
        IntVariable J   = new IntVariable(net, 0, 9);
        IntVariable A   = new IntVariable(net, 0, 9);
        IntVariable V   = new IntVariable(net, 0, 9);
        IntVariable C   = new IntVariable(net, 0, 9);
        IntVariable R   = new IntVariable(net, 0, 9);
        IntVariable E   = new IntVariable(net, 0, 9);
        IntVariable M   = new IntVariable(net, 0, 9);
        IntVariable S   = new IntVariable(net, 0, 9);
        IntVariable O   = new IntVariable(net, 0, 9);
        IntVariable L   = new IntVariable(net, 0, 9);

        new NotEquals(net, new IntVariable[] { J, A, V, C, R, E, M, S, O, L });
        J.NotEquals(0);
        C.NotEquals(0);
        S.NotEquals(0);
        IntVariable JAVA   = J.Multiply(1000).Add(A.Multiply(100)).Add(V.Multiply(10)).Add(A);
        IntVariable CREAM  = C.Multiply(10000).Add(R.Multiply(1000)).Add(E.Multiply(100)).Add(A.Multiply(10)).Add(M);
        IntVariable SOLVER = S.Multiply(100000).Add(O.Multiply(10000)).Add(L.Multiply(1000)).Add(V.Multiply(100)).Add(E.Multiply(10)).Add(R);

        JAVA.Add(CREAM).Equals(SOLVER);
        Solver solver = new DefaultSolver(net);

        for (solver.Start(); solver.WaitNext(); solver.Resume())
        {
            Solution solution = solver.Solution;
            Console.Out.WriteLine(solution.GetIntValue(JAVA) + " + " + solution.GetIntValue(CREAM) + " = " + solution.GetIntValue(SOLVER));
        }
        solver.Stop();
        Console.ReadLine();
    }
Exemple #8
0
    public static void Main(String[] args)
    {
        // Create a constraint network
        Network net = new Network();
        // Declare variables
        IntVariable x = new IntVariable(net);
        IntVariable y = new IntVariable(net);
        // x >= 0
        x.Ge(0);
        // y >= 0
        y.Ge(0);
        // x + y == 7
        x.Add(y).Equals(7);
        // 2x + 4y == 20
        x.Multiply(2).Add(y.Multiply(4)).Equals(20);
        // Solve the problem
        Solver solver = new DefaultSolver(net);
        /*Solution solution = solver.findAll(Solution);
        int xv = solution.getIntValue(x);
        int yv = solution.getIntValue(y);
        Console.Out.WriteLine("x = " + xv + ", y = " + yv);
        */

        for (solver.Start(); solver.WaitNext(); solver.Resume()) {
        Solution solution = solver.Solution;
        int xv = solution.GetIntValue(x);
        int yv = solution.GetIntValue(y);
        Console.Out.WriteLine("x8 = " + xv + ", y = " + yv);
        }
        solver.Stop();

        //solver.findAll(new FirstStepHandler(x, y));
        Console.In.ReadLine();
    }
Exemple #9
0
 private void Prime(IntVariable variable)
 {
     this.variable = variable;
     value         = variable.Value;
     image.sprite  = sprite;
     displayValue  = value.ToString();
 }
Exemple #10
0
        public void Add_And_Get_Items()
        {
            const string var1Name = "var1name";
            const string var2Name = "var2name";
            const string var3Name = "var3name";

            var var1 = new IntVariable(1234);
            var var2 = new StringVariable("theValue");
            var var3 = new BoolVariable(true);

            var vg = new VariablesGroup
            {
                { var1Name, var1 },
                new KeyValuePair <string, IVariable>(var2Name, var2)
            };

            vg[var3Name] = var3;

            Assert.That(vg.Count, Is.EqualTo(3));
            Assert.That((int)vg[var1Name].GetValue() !, Is.EqualTo(1234));
            Assert.That((string)vg[var2Name].GetValue() !, Is.EqualTo("theValue"));
            Assert.That(vg.Keys.Count, Is.EqualTo(3));
            Assert.That(vg.ContainsKey(var1Name));
            Assert.That(vg.Values.Count, Is.EqualTo(3));
            Assert.That(vg.Values.Contains(var1));
            Assert.That(vg.Values.Contains(var2));
            Assert.That(vg.Values.Contains(var3));
            Assert.That(vg.ContainsKey(var2Name));
            Assert.That(vg.TryGetValue(var1Name + "False", out _), Is.False);
        }
    public void CreateNew()
    {
        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("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("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("bool");
            break;
        }
        c.NumberVariables++;
    }
 public ThiefStateNode(bool thiefOnly, IntVariable nbThief, float agentSpeed, SpiritAI ai)
 {
     this.thiefOnly  = thiefOnly;
     this.nbThief    = nbThief;
     this.agentSpeed = agentSpeed;
     this.ai         = ai;
 }
 private void UpdateDataBundlesIndex()
 {
     for (int i = 0; i < dataBundleCollection.Value.dataBundles.Count; i++)
     {
         dataBundleCollection.Value.dataBundles[i].SetOrUpdateValue("_Index", IntVariable.New(i));
     }
 }
Exemple #14
0
 void Start()
 {
     slot1Counter = Resources.Load <IntVariable>("ScriptsAndData/Data/ResourceManagement/1_Resource_Num");
     slot2Counter = Resources.Load <IntVariable>("ScriptsAndData/Data/ResourceManagement/2_Resource_Num");
     slot3Counter = Resources.Load <IntVariable>("ScriptsAndData/Data/ResourceManagement/3_Resource_Num");
     slot4Counter = Resources.Load <IntVariable>("ScriptsAndData/Data/ResourceManagement/4_Resource_Num");
 }
Exemple #15
0
 private void setSlotCounter(BlockElementData slotData, IntVariable slotCounter)
 {
     if (slotData != null)
     {
         slotData.SlotCounter = slotCounter;
     }
 }
Exemple #16
0
        public static void Main(string[] args)
        {
            Network net = new Network();

            IntVariable X = new IntVariable(net, 0, 708);
            IntVariable Y = new IntVariable(net, 0, 708);
            IntVariable Z = new IntVariable(net, 0, 708);
            IntVariable T = new IntVariable(net, 0, 708);

            X.Add(Y).Add(Z).Add(T).Equals(711);
            X.Ge(Y);
            Y.Ge(Z);
            Z.Ge(T);
            X.Multiply(Y).Multiply(Z).Multiply(T).Equals(711000000);
            Solver solver = new DefaultSolver(net);

            for (solver.Start(); solver.WaitNext(); solver.Resume())
            {
                Solution solution = solver.Solution;
                Console.Out.WriteLine();
                Console.Out.WriteLine(" {0:F} + {1:F} + {2:F} + {3:F} = {4:F} ",
                                      solution.GetIntValue(X) / 100.0, solution.GetIntValue(Y) / 100.0,
                                      solution.GetIntValue(Z) / 100.0, solution.GetIntValue(T) / 100.0, 7.11);
            }
            solver.Stop();
            Console.ReadLine();
        }
Exemple #17
0
 public ClientStateNode(bool clientOnly, IntVariable nbClient, float agentSpeed, SpiritAI ai)
 {
     this.clientOnly = clientOnly;
     this.nbClient   = nbClient;
     this.agentSpeed = agentSpeed;
     this.ai         = ai;
 }
Exemple #18
0
 public void RemoveFromTower(TowerUiData tower, IntVariable variable)
 {
     foreach (var modifiedCurrency in tower.ModifiedPrice.Where(p => p.Currency.Variable == variable))
     {
         modifiedCurrency.Amount.RemoveModifier(this);
     }
 }
Exemple #19
0
        internal void queens(int n)
        {
            var c   = 0;
            var net = new Network();
            var q   = new IntVariable[n];
            var u   = new IntVariable[n];
            var d   = new IntVariable[n];

            for (var i = 0; i < n; ++i)
            {
                q[i] = new IntVariable(net, 1, n);
                u[i] = q[i].Add(i);
                d[i] = q[i].Subtract(i);
            }
            new NotEquals(net, q);
            new NotEquals(net, u);
            new NotEquals(net, d);
            Solver solver = new DefaultSolver(net);

            for (solver.Start(); solver.WaitNext(); solver.Resume())
            {
                Solution solution = solver.Solution;
                sol[c] = new int[8];
                for (int i = 0; i < n; i++)
                {
                    sol[c][i] = solution.GetIntValue(q[i]);
                }
                c++;
            }
            solver.Stop();
        }
Exemple #20
0
 private void Initialize()
 {
     _beatEngine   = beatEngine;
     _verbLoader   = verbLoader;
     _gameState    = gameState;
     _timerHandler = timerHandler;
     _difficulty   = difficulty;
 }
Exemple #21
0
 public LineChecker(StateManager m, Board b, IntVariable s, IInputGiver giver)
 {
     _manager     = m;
     _board       = b;
     _score       = s;
     _giver       = giver;
     _checkNeeded = true;
 }
    private void Awake()
    {
        changeDataGameEvent = _changeDataGameEvent;
        s_coinAmount        = _coinAmount;
        s_starAmount        = _starAmount;

        LoadData();
    }
Exemple #23
0
        public void RemoveFromEnemy(EnemyInstance enemyInstance, IntVariable variable = null)
        {
            bool everyVariable = variable == null;

            foreach (var modifiedCurrency in GetDesiredCollection(enemyInstance).Where(l => everyVariable || l.Currency.Variable == variable))
            {
                modifiedCurrency.Amount.RemoveModifier(this);
            }
        }
        public ScoreDisplayer(IntVariable s, TextMeshProUGUI t)
        {
            var score = s;

            score.Value           = 0;
            score.OnValueChanged += UpdateScore;
            _scoreText            = t;
            _scoreText.text       = score.Value.ToString();
        }
Exemple #25
0
        internal static void signExample()
        {
            Network     net = new Network();
            IntVariable x   = new IntVariable(net, -2, 2, "x");
            IntVariable y   = x.Sign();

            y.Name = "y";
            runExample(net, Solver.Default);
        }
Exemple #26
0
        private void Start()
        {
            var reference = GetComponent <SlotParameter>();

            if (reference)
            {
                number = reference.Value.number;
            }
        }
Exemple #27
0
    void InjectPlayerScore(GameObject parentGameObject, IntVariable playerScore)
    {
        PlayerScoreManager[] playerScoresManager = parentGameObject.GetComponentsInChildren <PlayerScoreManager>(true);

        foreach (PlayerScoreManager playerScoreManager in playerScoresManager)
        {
            playerScoreManager.PlayerScoreVariable = playerScore;
        }
    }
    private void TrySaveVariable(IntVariable var)
    {
        if (!SaveOnReset)
        {
            return;
        }

        SaveLoader.SaveInt(var);
    }
Exemple #29
0
        private void Awake()
        {
            var literal = GetComponent <IntVariableParameter>();

            if (literal)
            {
                number = literal.Value;
            }
        }
Exemple #30
0
 private void InitVariables()
 {
     _scoreVariable    = ScriptableObject.CreateInstance <IntVariable>();
     _currentPiece     = ScriptableObject.CreateInstance <PieceVariable>();
     _nextPiece        = ScriptableObject.CreateInstance <PieceVariable>();
     _currentMoveDelay = ScriptableObject.CreateInstance <FloatVariable>();
     _hardDrop         = ScriptableObject.CreateInstance <BoolVariable>();
     currentGiver.SetBoard(_currentBoard);
 }
Exemple #31
0
        private static IntVariable sum(IntVariable[] v)
        {
            IntVariable sum = null;

            for (int i = 0; i < v.Length; i++)
            {
                sum = (sum == null) ? v[i] : sum.Add(v[i]);
            }
            return(sum);
        }
Exemple #32
0
 internal static IntVariable adjacentSum(int i, int j)
 {
     IntVariable s = new IntVariable(net, 0);
     if (i - 1 >= 0 && v[i - 1][j] != null)
         s = s.Add(v[i - 1][j]);
     if (i + 1 < m && v[i + 1][j] != null)
         s = s.Add(v[i + 1][j]);
     if (j - 1 >= 0 && v[i][j - 1] != null)
         s = s.Add(v[i][j - 1]);
     if (j + 1 < n && v[i][j + 1] != null)
         s = s.Add(v[i][j + 1]);
     return s;
 }
Exemple #33
0
    internal static void golomb(int m)
    {
        int n = (1 << (m - 1)) - 1;
        Network net = new Network();
        IntVariable[] a = new IntVariable[m];
        a[0] = new IntVariable(net, 0);
        for (int i = 1; i < m; i++)
        {
            a[i] = new IntVariable(net, 1, n);
            a[i - 1].Lt(a[i]);
        }
        IntVariable[] d = new IntVariable[m * (m - 1) / 2];
        int k = 0;
        for (int i = 0; i < m; i++)
        {
            for (int j = i + 1; j < m; j++)
            {
                d[k++] = a[j].Subtract(a[i]);
            }
        }
        //d[0].Lt((d[m - 1]));
        new NotEquals(net, d);
        net.Objective=a[m - 1];

        Solver solver = new DefaultSolver(net, Solver.Minimize);
        Solution solution;
        for (solver.Start(); solver.WaitNext(); solver.Resume())
        {
            solution = solver.Solution;
            //estSolution = solver.BestSolution;

            Console.Out.Write("0");
                   for (int i = 1; i < m; i++)
                   {
                       Console.Out.Write("," + solution.GetIntValue(a[i]));
                   }
                   Console.Out.WriteLine();
        }
        solver.Stop();
        solution = solver.FindBest();
        Console.Out.WriteLine("===========================");
        Console.Out.Write("0");
        for (int i = 1; i < m; i++)
        {
            Console.Out.Write("," + solution.GetIntValue(a[i]));
        }
        Console.Out.WriteLine();
    }
Exemple #34
0
 public static void Main(String[] args)
 {
     Network net = new Network();
     int n = 3;
     int sum = n * (n * n + 1) / 2;
     IntVariable[][] v = new IntVariable[n][];
     for (int i = 0; i < n; i++)
     {
         v[i] = new IntVariable[n];
     }
     for (int i = 0; i < n; i++)
         for (int j = 0; j < n; j++)
             v[i][j] = new IntVariable(net, 1, n * n);
     IntVariable[] u = new IntVariable[] { v[0][0], v[0][1], v[0][2], v[1][0], v[1][1], v[1][2], v[2][0], v[2][1], v[2][2] };
     new NotEquals(net, u);
     for (int i = 0; i < n; i++)
         v[i][0].Add(v[i][1]).Add(v[i][2]).Equals(sum);
     for (int j = 0; j < n; j++)
         v[0][j].Add(v[1][j]).Add(v[2][j]).Equals(sum);
     v[0][0].Add(v[1][1]).Add(v[2][2]).Equals(sum);
     v[0][2].Add(v[1][1]).Add(v[2][0]).Equals(sum);
     Solver solver = new DefaultSolver(net);
     for (solver.Start(); solver.WaitNext(); solver.Resume())
     {
         Solution solution = solver.Solution;
         for (int i = 0; i < n; i++)
         {
             for (int j = 0; j < n; j++)
                 Console.Out.Write(solution.GetIntValue(v[i][j]) + " ");
             Console.Out.WriteLine();
         }
         Console.Out.WriteLine();
     }
     solver.Stop();
     Console.ReadLine();
 }
Exemple #35
0
    public static void magic(int n)
    {
        Network net = new Network();
        IntVariable[][] square = new IntVariable[n][];
        for (int i = 0; i < n; i++)
        {
            square[i] = new IntVariable[n];
        }

        // All squares have different numbers 1 .. n*n
        IntVariable[] v = new IntVariable[n * n];
        int k = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                square[i][j] = new IntVariable(net, 1, n * n);
                v[k++] = square[i][j];
            }
        }
        new NotEquals(net, v);

        // Sum of each row is n*(n*n+1)/2
        IntVariable s;
        int sum = n * (n * n + 1) / 2;
        for (int i = 0; i < n; i++)
        {
            s = square[i][0];
            for (int j = 1; j < n; j++)
                s = s.Add(square[i][j]);
            s.Equals(sum);
        }

        // Sum of each column is n*(n*n+1)/2
        for (int j = 0; j < n; j++)
        {
            s = square[0][j];
            for (int i = 1; i < n; i++)
                s = s.Add(square[i][j]);
            s.Equals(sum);
        }

        // Sum of down-diagonal is n*(n*n+1)/2
        s = square[0][0];
        for (int i = 1; i < n; i++)
            s = s.Add(square[i][i]);
        s.Equals(sum);

        // Sum of up-diagonal is n*(n*n+1)/2
        s = square[0][n - 1];
        for (int i = 1; i < n; i++)
            s = s.Add(square[i][n - i - 1]);
        s.Equals(sum);

        // Left-upper corner is minimum
        square[0][0].Lt(square[0][n - 1]);
        square[0][0].Lt(square[n - 1][0]);
        square[0][0].Lt(square[n - 1][n - 1]);

        // Upper-right is less than lower-left
        square[0][n - 1].Lt(square[n - 1][0]);

        Console.Out.WriteLine("Start");
        long time0 = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        int count = 0;
        bool output = true;
        Solver solver = new DefaultSolver(net);
        for (solver.Start(); solver.WaitNext(); solver.Resume())
        {
            if (output)
            {
                Solution solution = solver.Solution;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        Console.Out.Write(solution.GetIntValue(square[i][j]) + " ");
                    }
                    Console.Out.WriteLine();
                }
                Console.Out.WriteLine();
            }
            count++;
        }
        solver.Stop();
        int time = (int)(((DateTime.Now.Ticks - 621355968000000000) / 10000 - time0) / 1000);
        Console.Out.WriteLine(count + " solutions found in " + time + " seconds");
    }
Exemple #36
0
 public FirstStepHandler(IntVariable x, IntVariable y)
 {
     this.x = x;
     this.y = y;
 }
Exemple #37
0
 private static void ft06(Network net)
 {
     var n = 37;
     var v = new IntVariable[n];
     for (var i = 0; i < v.Length; i++)
     {
         v[i] = new IntVariable(net, 0, IntDomain.MaxValue);
     }
     var jobs = new[]
                	{
                		new[] {v[1], v[2], v[3], v[4], v[5], v[6], v[0]},
                		new[] {v[7], v[8], v[9], v[10], v[11], v[12], v[0]},
                		new[] {v[13], v[14], v[15], v[16], v[17], v[18], v[0]},
                		new[] {v[19], v[20], v[21], v[22], v[23], v[24], v[0]},
                		new[] {v[25], v[26], v[27], v[28], v[29], v[30], v[0]},
                		new[] {v[31], v[32], v[33], v[34], v[35], v[36], v[0]}
                	};
     var jobs_pt = new[]
                   	{
                   		new[] {1, 3, 6, 7, 3, 6},
                   		new[] {8, 5, 10, 10, 10, 4},
                   		new[] {5, 4, 8, 9, 1, 7},
                   		new[] {5, 5, 5, 3, 8, 9},
                   		new[] {9, 3, 5, 4, 3, 1},
                   		new[] {3, 3, 9, 10, 4, 1}
                   	};
     var machines = new[]
                    	{
                    		new[] {v[2], v[11], v[16], v[20], v[29], v[34]},
                    		new[] {v[3], v[7], v[17], v[19], v[26], v[31]},
                    		new[] {v[1], v[8], v[13], v[21], v[25], v[36]},
                    		new[] {v[4], v[12], v[14], v[22], v[30], v[32]},
                    		new[] {v[6], v[9], v[18], v[23], v[27], v[35]},
                    		new[] {v[5], v[10], v[15], v[24], v[28], v[33]}
                    	};
     var machines_pt = new[]
                       	{
                       		new[] {3, 10, 9, 5, 3, 10},
                       		new[] {6, 8, 1, 5, 3, 3},
                       		new[] {1, 5, 5, 5, 9, 1},
                       		new[] {7, 4, 4, 3, 1, 3},
                       		new[] {6, 10, 7, 8, 5, 4},
                       		new[] {3, 10, 8, 9, 4, 9}
                       	};
     for (int j = 0; j < jobs.Length; j++)
     {
         new Sequential(net, jobs[j], jobs_pt[j]);
     }
     for (int m = 0; m < machines.Length; m++)
     {
         new Serialized(net, machines[m], machines_pt[m]);
     }
     net.Objective = v[0];
 }
Exemple #38
0
    internal static void setProblem()
    {
        net = new Network();

        // Set constraint variables
        v = new IntVariable[m][];
        for (int i = 0; i < m; i++)
        {
            v[i] = new IntVariable[n];
        }
        _vsum = new IntVariable[m][];
        for (int i2 = 0; i2 < m; i2++)
        {
            _vsum[i2] = new IntVariable[n];
        }
        _hsum = new IntVariable[m][];
        for (int i3 = 0; i3 < m; i3++)
        {
            _hsum[i3] = new IntVariable[n];
        }
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                v[i][j] = null;
                if (puzzle[i][j].Equals("-"))
                {
                    v[i][j] = new IntVariable(net, 0, 1);
                }
                _vsum[i][j] = null;
                _hsum[i][j] = null;
            }
        }
        // Set constraints
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (puzzle[i][j].Equals("-"))
                {
                    IntVariable vsum_ = vsum(i, j);
                    IntVariable hsum_ = hsum(i, j);
                    vsum_.Add(hsum_).Subtract(v[i][j]).Ge(1);
                }
                else if (puzzle[i][j].Equals("^\\d$"))
                {
                    int sum = Int32.Parse(puzzle[i][j]);
                    IntVariable asum = adjacentSum(i, j);
                    asum.Equals(sum);
                }
            }
        }
    }
 public FastOutputPort(PIOReferenceVariable pio, IntVariable bitmask)
 {
     this.pio=pio;
       this.bitmask=bitmask;
 }