Esempio n. 1
0
        private void PutObj(mosek.Task task)
        {
            if (GoalCount > 1)
            {
                throw new MosekMsfUnsupportedFeatureException("Multiple goals.");
            }

            foreach (ILinearGoal goal in Goals)
            {
                if (goal.Enabled)
                {
                    if (goal.Minimize)
                    {
                        task.putobjsense(mosek.objsense.minimize);
                    }
                    else
                    {
                        task.putobjsense(mosek.objsense.maximize);
                    }

                    if (IsRow(goal.Index))
                    {
                        goalUsed = goal;

                        double mul = -(1.0 / (double)GetCoefficient(goal.Index, goal.Index));
                        foreach (LinearEntry e in GetRowEntries(goal.Index))
                        {
                            task.putcj(varMap[e.Index], (double)e.Value * mul);
                        }
                        foreach (QuadraticEntry e in GetRowQuadraticEntries(goal.Index))
                        {
                            double mul2 = 1.0;
                            if (e.Index2 == e.Index1)
                            {
                                mul2 = 2.0;
                            }

                            /* We assume that either q_ij or q_ji is nonzero, not both.
                             * We put all elements in the lower triangular part.  */
                            int index1   = varMap[e.Index1];
                            int index2   = varMap[e.Index2];
                            int ltIndex1 = System.Math.Max(index1, index2);
                            int ltIndex2 = System.Math.Min(index1, index2);

                            task.putqobjij(ltIndex1, ltIndex2, (double)e.Value * mul * mul2);
                        }
                    }
                    else
                    {
                        task.putcj(varMap[goal.Index], 1.0);
                    }
                }
            }
        }