Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.79 KB | None | 0 0
  1. function update_center(ctr_proximal, nVariables, center)
  2.     for i in 1:nVariables
  3.         JuMP.setRHS(ctr_proximal[i], center[i])
  4.     end
  5. end
  6. function launch_proximal(X, xMin, xMax)
  7.     master = Model(solver=CplexSolver(CPX_PARAM_THREADS=1, CPX_PARAM_QPMETHOD=2, CPXPARAM_ScreenOutput=0));
  8.     nVariables, nCassures = size(X)
  9.     x, α = build_master_cutting_plane(X, master, xMin, xMax)
  10.     var_proximal = @variable(master, var_proximal[1:nVariables])
  11.     ctr_proximal = @constraint(master, ctr_proximal[i in 1:nVariables], x[i]==var_proximal[i])
  12.  
  13.     stop = false
  14.     lb = -1e20
  15.     ub = +1e20
  16.     n_ite=0
  17.  
  18.     best_ub = ub
  19.     prediction = 0
  20.     nb_ss=0
  21.     nb_ns=0
  22.     nb_update = 3
  23.     # nb_update=3
  24.     step="NONE"
  25.     weight=1e1
  26.     tol=1e-1
  27.  
  28.  
  29.    
  30.     center=Base.zeros(nVariables)
  31.     update_center(ctr_proximal, nVariables, center)
  32.     while ! stop
  33.         n_ite+=1
  34.         solve(master)
  35.         lb = getvalue(α)
  36.  
  37.         x_value, rhs, sub_gradient = build_cut(X, x)
  38.         ub = rhs
  39.  
  40.         prediction = lb-best_ub
  41.  
  42.     if ub-best_ub <= tol*prediction
  43.         step="SS"
  44.        
  45.             best_ub = min(ub, best_ub)
  46.         nb_ss+=1
  47.         nb_ns = 0
  48.         if nb_ss == 10
  49.             weight/=2
  50.             nb_ss = 0
  51.         end
  52.         update_center(ctr_proximal, nVariables, x_value)
  53.     else
  54.         step="NS"
  55.         nb_ns+=1
  56.         nb_ss = 0
  57.         if nb_ns == 10
  58.             weight*=2
  59.             nb_ns = 0
  60.         end
  61.     end
  62.    
  63.  
  64.     @objective(master, :Min, α +sum(weight*var_proximal[i]^2 for i in 1:nVariables))
  65.    
  66.         #best_ub = min(ub, best_ub)
  67.  
  68.         if n_ite>1 && -prediction < EPS
  69.             stop = true
  70.         else
  71.             @constraint(master, α>=rhs+sum( sub_gradient[i] * (x[i]-x_value[i]) for i in 1:nVariables))
  72.         end
  73.         @printf("%10d%6s%20.10E%20.10E%20.10E%20.10E\n", n_ite, step, weight, lb, ub, prediction)
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement