Exemplo n.º 1
0
        public ClSymbolicWeight Times(double n)
        {
            ClSymbolicWeight clsw = (ClSymbolicWeight)Clone();

            for (int i = 0; i < _values.Length; i++)
            {
                clsw._values[i] *= n;
            }

            return(clsw);
        }
Exemplo n.º 2
0
        public bool Equal(ClSymbolicWeight clsw1)
        {
            for (int i = 0; i < _values.Length; i++)
            {
                if (_values[i] != clsw1._values[i])
                {
                    return(false);
                }
            }

            return(true); // they are equal
        }
Exemplo n.º 3
0
        public ClSymbolicWeight Subtract(ClSymbolicWeight clsw1)
        {
            // Assert(clsw1.CLevels == CLevels);
            ClSymbolicWeight clsw = (ClSymbolicWeight)Clone();

            for (int i = 0; i < _values.Length; i++)
            {
                clsw._values[i] -= clsw1._values[i];
            }

            return(clsw);
        }
Exemplo n.º 4
0
        public ClSymbolicWeight DivideBy(double n)
        {
            // Assert(n != 0);
            ClSymbolicWeight clsw = (ClSymbolicWeight)Clone();

            for (int i = 0; i < _values.Length; i++)
            {
                clsw._values[i] /= n;
            }

            return(clsw);
        }
Exemplo n.º 5
0
        public bool LessThanOrEqual(ClSymbolicWeight clsw1)
        {
            // Assert(clsw1.CLevels == CLevels);

            for (int i = 0; i < _values.Length; i++)
            {
                if (_values[i] < clsw1._values[i])
                {
                    return(true);
                }
                else if (_values[i] > clsw1._values[i])
                {
                    return(false);
                }
            }

            return(true); // they are equal
        }
Exemplo n.º 6
0
        // TODO: comparison operators (<, <=, >, >=, ==)
        public bool LessThan(ClSymbolicWeight clsw1)
        {
            // Assert(clsw1.CLevels == CLevels);

            for (var i = 0; i < _values.Count; i++)
            {
                if (_values[i] < clsw1._values[i])
                {
                    return(true);
                }
                if (_values[i] > clsw1._values[i])
                {
                    return(false);
                }
            }

            return(false); // they are equal
        }
Exemplo n.º 7
0
 public bool GreaterThan(ClSymbolicWeight clsw1)
 {
     return(!LessThan(clsw1));
 }
Exemplo n.º 8
0
 public bool GreaterThan(ClSymbolicWeight clsw1)
 {
   return !LessThan(clsw1);
 }
Exemplo n.º 9
0
 public bool Equal(ClSymbolicWeight clsw1)
 {
   for (int i = 0; i < _values.Length; i++)
   {
     if (_values[i] != clsw1._values[i])
       return false;
   }
   
   return true; // they are equal
 }
Exemplo n.º 10
0
 public ClStrength(string name, double w1, double w2, double w3)
 {
   _name = name;
   _symbolicWeight = new ClSymbolicWeight(w1, w2, w3);
 }
Exemplo n.º 11
0
 public ClSymbolicWeight Subtract(ClSymbolicWeight clsw1)
 {
   // Assert(clsw1.CLevels == CLevels);
   ClSymbolicWeight clsw = (ClSymbolicWeight) Clone();
   
   for (int i = 0; i < _values.Length; i++)
   {
     clsw._values[i] -= clsw1._values[i];
   }
   
   return clsw;
 }
Exemplo n.º 12
0
        private ClLinearExpression NewExpression(ClConstraint cn,
                                                 ICollection <ClAbstractVariable> eplusEminus,
                                                 ClDouble prevEConstant)
        {
            ClLinearExpression cnExpr = cn.Expression;
            ClLinearExpression expr   = new ClLinearExpression(cnExpr.Constant);
            ClSlackVariable    eminus;
            var cnTerms = cnExpr.Terms;

            foreach (ClAbstractVariable v in cnTerms.Keys)
            {
                double             c = (cnTerms[v]).Value;
                ClLinearExpression e = RowExpression(v);
                if (e == null)
                {
                    expr.AddVariable(v, c);
                }
                else
                {
                    expr.AddExpression(e, c);
                }
            }

            if (cn.IsInequality)
            {
                ++_slackCounter;
                ClSlackVariable slackVar = new ClSlackVariable(_slackCounter, "s");
                expr.SetVariable(slackVar, -1);
                _markerVars.Add(cn, slackVar);
                if (!cn.Strength.IsRequired)
                {
                    ++_slackCounter;
                    eminus = new ClSlackVariable(_slackCounter, "em");
                    expr.SetVariable(eminus, 1.0);
                    ClLinearExpression zRow = RowExpression(_objective);
                    ClSymbolicWeight   sw   = cn.Strength.SymbolicWeight.Times(cn.Weight);
                    zRow.SetVariable(eminus, sw.AsDouble());
                    InsertErrorVar(cn, eminus);
                    NoteAddedVariable(eminus, _objective);
                }
            }
            else
            {
                // cn is an equality
                if (cn.Strength.IsRequired)
                {
                    ++_dummyCounter;
                    ClDummyVariable dummyVar = new ClDummyVariable(_dummyCounter, "d");
                    expr.SetVariable(dummyVar, 1.0);
                    _markerVars.Add(cn, dummyVar);
                }
                else
                {
                    ++_slackCounter;
                    ClSlackVariable eplus = new ClSlackVariable(_slackCounter, "ep");
                    eminus = new ClSlackVariable(_slackCounter, "em");

                    expr.SetVariable(eplus, -1.0);
                    expr.SetVariable(eminus, 1.0);
                    _markerVars.Add(cn, eplus);
                    ClLinearExpression zRow    = RowExpression(_objective);
                    ClSymbolicWeight   sw      = cn.Strength.SymbolicWeight.Times(cn.Weight);
                    double             swCoeff = sw.AsDouble();
                    zRow.SetVariable(eplus, swCoeff);
                    NoteAddedVariable(eplus, _objective);
                    zRow.SetVariable(eminus, swCoeff);
                    NoteAddedVariable(eminus, _objective);
                    InsertErrorVar(cn, eminus);
                    InsertErrorVar(cn, eplus);
                    if (cn.IsStayConstraint)
                    {
                        _stayPlusErrorVars.Add(eplus);
                        _stayMinusErrorVars.Add(eminus);
                    }
                    else if (cn.IsEditConstraint)
                    {
                        eplusEminus.Add(eplus);
                        eplusEminus.Add(eminus);
                        prevEConstant.Value = cnExpr.Constant;
                    }
                }
            }

            if (expr.Constant < 0)
            {
                expr.MultiplyMe(-1);
            }

            return(expr);
        }
Exemplo n.º 13
0
 public ClStrength(string name, double w1, double w2, double w3)
 {
     _name           = name;
     _symbolicWeight = new ClSymbolicWeight(w1, w2, w3);
 }
Exemplo n.º 14
0
 public ClStrength(string name, ClSymbolicWeight symbolicWeight)
 {
     _name           = name;
     _symbolicWeight = symbolicWeight;
 }
Exemplo n.º 15
0
        private ClSymbolicWeight Add(ClSymbolicWeight clsw1)
        {
            // Assert(clws.CLevels == CLevels);

            return(new ClSymbolicWeight(_values.Select((a, i) => a + clsw1._values[i]).ToArray()));
        }
Exemplo n.º 16
0
        public bool Equal(ClSymbolicWeight clsw1)
        {
// ReSharper disable CompareOfFloatsByEqualityOperator
            return(!_values.Where((t, i) => t != clsw1._values[i]).Any());
// ReSharper restore CompareOfFloatsByEqualityOperator
        }
Exemplo n.º 17
0
    public bool LessThanOrEqual(ClSymbolicWeight clsw1)
    {
      // Assert(clsw1.CLevels == CLevels);

      for (int i = 0; i < _values.Length; i++)
      {
        if (_values[i] < clsw1._values[i])
          return true;
        else if (_values[i] > clsw1._values[i])
          return false;
      }

      return true; // they are equal
    }
Exemplo n.º 18
0
 public ClStrength(string name, ClSymbolicWeight symbolicWeight)
 {
   _name = name;
   _symbolicWeight = symbolicWeight;
 }