Skip to content

Commit

Permalink
updated Examples to new type hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
timueh committed Sep 11, 2019
1 parent e24cf95 commit caa8612
Show file tree
Hide file tree
Showing 9 changed files with 2,939 additions and 784 deletions.
207 changes: 185 additions & 22 deletions examples/DCsOPF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -84,9 +84,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"5×4 Array{Float64,2}:\n",
" 0.0 -0.381167 -0.170689 -0.0435176\n",
" 0.0 -0.434314 -0.582034 -0.148391 \n",
" 0.0 -0.184519 -0.247277 -0.808091 \n",
" 0.0 -0.618833 0.170689 0.0435176\n",
" 0.0 0.184519 0.247277 -0.191909 "
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = [ -1 1 0 0; -1 0 1 0; -1 0 0 1 ; 0 1 -1 0; 0 0 -1 1] # incidence matrix\n",
"Nl, N = size(A,1), size(A,2)\n",
Expand All @@ -103,9 +119,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"([10.0, 10.0, 10.0, 10.0, 10.0], [-10.0, -10.0, -10.0, -10.0, -10.0])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Cp, Cd = [1 0; 0 0; 0 0; 0 1], [0 0; 1 0; 0 1; 0 0 ] # book-keeping\n",
"Ng, Nd = size(Cp,2), size(Cd,2) \n",
Expand All @@ -124,12 +151,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"deg = 1\n",
"opq = [OrthoPolyQ(\"uniform01\",deg; Nrec=5*deg), OrthoPolyQ(\"uniform01\",deg; Nrec=5*deg)]\n",
"opq = [Uniform01OrthoPoly(deg; Nrec=5*deg), Uniform01OrthoPoly(deg; Nrec=5*deg)]\n",
"mop = MultiOrthoPoly(opq, deg)\n",
"Npce = mop.dim"
]
Expand All @@ -143,13 +181,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Float64,1}:\n",
" 2.0 \n",
" 0.6928203230275509"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d = zeros(Nd,Npce) # PCE coefficients of load\n",
"d[1,[1,2]] = convert2affinePCE(mop.uni[1].op.name, 1., 0.1, kind=:μσ)\n",
"d[2,[1,3]] = convert2affinePCE(mop.uni[2].op.name, 2., 0.2, kind=:μσ)"
"d[1,[1,2]] = convert2affinePCE(1., 0.1, mop.uni[1], kind=\"μσ\")\n",
"d[2,[1,3]] = convert2affinePCE(2., 0.2, mop.uni[2], kind=\"μσ\")"
]
},
{
Expand All @@ -162,9 +213,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"buildSOC (generic function with 1 method)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function buildSOC(x::Vector,mop::MultiOrthoPoly)\n",
" t = [ sqrt(Tensor(2,mop).get([i,i])) for i in 0:mop.dim-1 ]\n",
Expand All @@ -181,9 +243,63 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Problem\n",
" Name : \n",
" Objective sense : min \n",
" Type : CONIC (conic optimization problem)\n",
" Constraints : 45 \n",
" Cones : 14 \n",
" Scalar variables : 48 \n",
" Matrix variables : 0 \n",
" Integer variables : 0 \n",
"\n",
"Optimizer started.\n",
"Presolve started.\n",
"Linear dependency checker started.\n",
"Linear dependency checker terminated.\n",
"Eliminator - tries : 0 time : 0.00 \n",
"Lin. dep. - tries : 1 time : 0.00 \n",
"Lin. dep. - number : 0 \n",
"Presolve terminated. Time: 0.01 \n",
"Problem\n",
" Name : \n",
" Objective sense : min \n",
" Type : CONIC (conic optimization problem)\n",
" Constraints : 45 \n",
" Cones : 14 \n",
" Scalar variables : 48 \n",
" Matrix variables : 0 \n",
" Integer variables : 0 \n",
"\n",
"Optimizer - threads : 4 \n",
"Optimizer - solved problem : the dual \n",
"Optimizer - Constraints : 3\n",
"Optimizer - Cones : 14\n",
"Optimizer - Scalar variables : 42 conic : 42 \n",
"Optimizer - Semi-definite variables: 0 scalarized : 0 \n",
"Factor - setup time : 0.00 dense det. time : 0.00 \n",
"Factor - ML order time : 0.00 GP order time : 0.00 \n",
"Factor - nonzeros before factor : 6 after factor : 6 \n",
"Factor - dense dim. : 0 flops : 2.96e+02 \n",
"ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME \n",
"0 2.4e+00 2.7e-01 3.8e+01 0.00e+00 4.080826751e+01 -1.091917325e+02 1.0e+00 0.03 \n",
"1 1.9e-01 2.1e-02 2.9e+00 -3.24e-01 4.001610160e+01 1.412604826e+01 8.0e-02 0.04 \n",
"2 2.0e-02 2.2e-03 9.6e-01 8.89e-01 3.976195039e+01 3.688206327e+01 8.4e-03 0.04 \n",
"3 2.2e-03 2.5e-04 3.3e-01 9.86e-01 3.926857120e+01 3.894655502e+01 9.2e-04 0.04 \n",
"4 3.3e-06 3.8e-07 1.3e-02 9.98e-01 3.921416676e+01 3.921366930e+01 1.4e-06 0.04 \n",
"5 9.7e-11 1.1e-11 1.6e-09 1.00e+00 3.921411605e+01 3.921411603e+01 4.1e-11 0.04 \n",
"Optimizer terminated. Time: 0.11 \n",
"\n"
]
}
],
"source": [
"model = Model(with_optimizer(Mosek.Optimizer))\n",
"@variable(model, p[i in 1:Ng,j in 1:Npce], base_name=\"p\")\n",
Expand All @@ -206,9 +322,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"([5.85252e-9 -6.8734e-10 -1.45066e-9; 3.0 0.34641 0.69282], [-0.853098 -0.147115 -0.148407; -2.04356 -0.201855 -0.506053; … ; -0.146902 -0.199295 0.148407; 0.103347 -0.00256 0.0383604], 39.21411604774516)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@assert termination_status(model) == MOI.OPTIMAL \"Model not solved to optimality.\"\n",
"psol, plsol, obj = value.(p), value.(pl), objective_value(model)"
Expand All @@ -225,9 +352,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Array{Float64,2},1}:\n",
" [5.85252e-9 2.14739e-19]\n",
" [3.0 0.05] "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p_moments = [ [mean(psol[i,:],mop) var(psol[i,:],mop) ] for i in 1:Ng ]"
]
Expand All @@ -241,12 +381,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"5-element Array{Array{Float64,2},1}:\n",
" [-0.853098 0.00363895]\n",
" [-2.04356 0.0247363] \n",
" [-3.10335 0.0544049] \n",
" [-0.146902 0.00514526]\n",
" [0.103347 0.000123173]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pbr_moments = [ [mean(plsol[i,:],mop) var(plsol[i,:],mop) ] for i in 1:Nl ]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit caa8612

Please sign in to comment.