Exemple #1
0
        public override void Main()
        {
            double bestx = EPS;
            int    besti = -1;
            int    bestj = -1;
            int    num   = _sos.Length;

            INumVar[] var = null;
            double[]  x   = null;

            for (int i = 0; i < num; ++i)
            {
                if (GetSOSFeasibility(_sos[i])
                    .Equals(Cplex.IntegerFeasibilityStatus.Infeasible))
                {
                    var = _sos[i].NumVars;
                    x   = GetValues(var);

                    int n = var.Length;
                    for (int j = 0; j < n; ++j)
                    {
                        double inf = System.Math.Abs(x[j] - System.Math.Round(x[j]));
                        if (inf > bestx)
                        {
                            bestx = inf;
                            besti = i;
                            bestj = j;
                        }
                    }
                }
            }

            if (besti >= 0)
            {
                var = _sos[besti].NumVars;
                int n = var.Length;

                Cplex.BranchDirection[] dir = new Cplex.BranchDirection[n];
                double[] val = new double[n];

                for (int j = 0; j < n; ++j)
                {
                    if (j != bestj)
                    {
                        dir[j] = Cplex.BranchDirection.Down;
                        val[j] = 0.0;
                    }
                    else
                    {
                        dir[j] = Cplex.BranchDirection.Up;
                        val[j] = 1.0;
                    }
                }
                MakeBranch(var, val, dir, ObjValue);
                MakeBranch(var[bestj], 0.0,
                           Cplex.BranchDirection.Down, ObjValue);
            }
        }
Exemple #2
0
 public override void Main() {
    double bestx = EPS;
    int    besti = -1;
    int    bestj = -1;
    int    num   = _sos.Length;
  
    INumVar[] var = null;
    double[]  x   = null;
  
    for (int i = 0; i < num; ++i) {
       if ( GetSOSFeasibility(_sos[i]) 
            .Equals(Cplex.IntegerFeasibilityStatus.Infeasible) ) {
          var = _sos[i].NumVars;
          x = GetValues(var);
        
          int n = var.Length;
          for (int j = 0; j < n; ++j) {
             double inf = System.Math.Abs(x[j] - System.Math.Round(x[j]));
             if ( inf > bestx ) {
                bestx = inf;
                besti = i;
                bestj = j;
             }
          }
       }
    }
  
    if ( besti >= 0 ) {
       var = _sos[besti].NumVars;
       int n = var.Length;
     
       Cplex.BranchDirection[] dir = new Cplex.BranchDirection[n];
       double[]                   val = new double[n];
     
       for (int j = 0; j < n; ++j) {
          if ( j != bestj ) {
             dir[j] = Cplex.BranchDirection.Down;
             val[j] = 0.0;
          } else {
             dir[j] = Cplex.BranchDirection.Up;
             val[j] = 1.0;
          }
       }
       MakeBranch(var, val, dir, ObjValue);
       MakeBranch(var[bestj], 0.0, 
                  Cplex.BranchDirection.Down, ObjValue);
    }      
 }