Skip to content

Commit

Permalink
Finally green
Browse files Browse the repository at this point in the history
  • Loading branch information
xhub committed Feb 25, 2020
1 parent c751adc commit bcae9ae
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ environment:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0-latest-win64.exe"
GAMS_URL: "https://d37drm4t2jghv5.cloudfront.net/distributions/25.1.3/windows/windows_x64_64.exe"

- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.1/julia-1.3-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.3/julia-1.3-latest-win64.exe"
GAMS_URL: "https://d37drm4t2jghv5.cloudfront.net/distributions/25.1.3/windows/windows_x64_64.exe"

PATH: 'C:\projects\gams;%PATH%'
Expand Down
72 changes: 44 additions & 28 deletions examples/ovf_loss_equil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ if !isdef(:ovf_formulations); ovf_formulations = ["equilibrium"] end

@testset "Equilibrium loss test: penalty = $penalty_name; ovf_formulation = $ovf_formulation" for penalty_name in penalty_names, ovf_formulation in ovf_formulations

if ovf_formulation == "dual"
if penalty_name == "hubnik"
n_MP = 2
else
n_MP = 3
end
else
n_MP = 5
end

m = direct_model(ReSHOP.Optimizer(;ovf_formulation=ovf_formulation))

fit_model = EMP.Model(m)

mps = [MathPrgm(fit_model) for i=1:5]
mps = [MathPrgm(fit_model) for i=1:n_MP]

EquilibriumProblem(fit_model, mps)

Expand Down Expand Up @@ -46,6 +56,7 @@ addovf!(fit_model, loss_var2, fit2, penalty_name, all_params[penalty_name])

@objectiveMP(mps[2], Min, loss_var2)

if n_MP >= 3
# primary unknonwn
@variableMP(mps[3], c3[j=1:1])
@variableMP(mps[3], d3)
Expand All @@ -62,37 +73,39 @@ addovf!(fit_model, loss_var3, fit3, penalty_name, all_params[penalty_name])

@objectiveMP(mps[3], Min, loss_var3)

# primary unknonwn
@variableMP(mps[4], c4[j=1:1])
@variableMP(mps[4], d4)
elseif n_MP >= 4
# primary unknonwn
@variableMP(mps[4], c4[j=1:1])
@variableMP(mps[4], d4)

# OVF variable
@variableMP(mps[4], loss_var4)
# OVF variable
@variableMP(mps[4], loss_var4)

# OVF arguments
@variableMP(mps[4], fit4[i=1:N]);
# OVF arguments
@variableMP(mps[4], fit4[i=1:N]);

@NLconstraintMP(mps[4], fiteqn4[i=1:N], fit4[i] == log(exp((y[i] - sum(c4[j]*x[i, j] for j=1:M) - d4) / sigma_y[i])));
@NLconstraintMP(mps[4], fiteqn4[i=1:N], fit4[i] == log(exp((y[i] - sum(c4[j]*x[i, j] for j=1:M) - d4) / sigma_y[i])));

addovf!(fit_model, loss_var4, fit4, penalty_name, all_params[penalty_name])
addovf!(fit_model, loss_var4, fit4, penalty_name, all_params[penalty_name])

@objectiveMP(mps[4], Min, loss_var4)
@objectiveMP(mps[4], Min, loss_var4)

# primary unknonwn
@variableMP(mps[5], c5[j=1:1])
@variableMP(mps[5], d5)
@variableMP(mps[5], c5[j=1:1])
@variableMP(mps[5], d5)

# OVF variable
@variableMP(mps[5], loss_var5)
# OVF variable
@variableMP(mps[5], loss_var5)

# OVF arguments
@variableMP(mps[5], fit5[i=1:N]);
# OVF arguments
@variableMP(mps[5], fit5[i=1:N]);

@constraintMP(mps[5], fiteqn5[i=1:N], pi*(y[i] - sum(c5[j]*x[i, j] for j=1:M) - d5) / sigma_y[i] == pi*fit5[i]);
@constraintMP(mps[5], fiteqn5[i=1:N], pi*(y[i] - sum(c5[j]*x[i, j] for j=1:M) - d5) / sigma_y[i] == pi*fit5[i]);

addovf!(fit_model, loss_var5, fit5, penalty_name, all_params[penalty_name])
addovf!(fit_model, loss_var5, fit5, penalty_name, all_params[penalty_name])

@objectiveMP(mps[5], Min, loss_var5)
@objectiveMP(mps[5], Min, loss_var5)
end


cmp_dir = joinpath(dirname(@__FILE__), "test_res")
Expand All @@ -114,19 +127,22 @@ occursin("hinge", penalty_name) && continue
@test isapprox(value.(fit2), file_ref[1:N], rtol=1e-4)
@test isapprox(value(loss_var2), unknown_ref[3], rtol=1e-4)

if n_MP >= 3
@test isapprox(value.(c3), [unknown_ref[1]], rtol=1e-4)
@test isapprox(value(d3), unknown_ref[2], rtol=1e-4)
@test isapprox(value.(fit3), file_ref[1:N], rtol=1e-4)
@test isapprox(value(loss_var3), unknown_ref[3], rtol=1e-4)

@test isapprox(value.(c4), [unknown_ref[1]], rtol=1e-4)
@test isapprox(value(d4), unknown_ref[2], rtol=1e-4)
@test isapprox(value.(fit4), file_ref[1:N], rtol=1e-4)
@test isapprox(value(loss_var4), unknown_ref[3], rtol=1e-4)
elseif n_MP >= 4
@test isapprox(value.(c4), [unknown_ref[1]], rtol=1e-4)
@test isapprox(value(d4), unknown_ref[2], rtol=1e-4)
@test isapprox(value.(fit4), file_ref[1:N], rtol=1e-4)
@test isapprox(value(loss_var4), unknown_ref[3], rtol=1e-4)

@test isapprox(value.(c5), [unknown_ref[1]], rtol=1e-4)
@test isapprox(value(d5), unknown_ref[2], rtol=1e-4)
@test isapprox(value.(fit5), file_ref[1:N], rtol=1e-4)
@test isapprox(value(loss_var5), unknown_ref[3], rtol=1e-4)
@test isapprox(value.(c5), [unknown_ref[1]], rtol=1e-4)
@test isapprox(value(d5), unknown_ref[2], rtol=1e-4)
@test isapprox(value.(fit5), file_ref[1:N], rtol=1e-4)
@test isapprox(value(loss_var5), unknown_ref[3], rtol=1e-4)
end

end
2 changes: 1 addition & 1 deletion test/gnep_river_basin.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using JuMP, ReSHOP, EMP
using Compat.Test
using Test

@testset "gnep river basin" begin

Expand Down
2 changes: 1 addition & 1 deletion test/ovf_loss_equil.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using JuMP, EMP, ReSHOP
using Compat, Compat.Test
using Compat, Test

# Data is from ``Data analysis recipes: Fitting a model to data'' by Hogg, Bovy & Lang
# available on https://arxiv.org/abs/1008.4686.
Expand Down
2 changes: 1 addition & 1 deletion test/ovf_loss_nl.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using JuMP, EMP, ReSHOP
using Compat.Test
using Test

# Data is from ``Data analysis recipes: Fitting a model to data'' by Hogg, Bovy & Lang
# available on https://arxiv.org/abs/1008.4686.
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#for undef and occursin
using Compat
using Compat.Test
using Test

#examples_path = joinpath(dirname(dirname(@__FILE__)), "examples")
#for example in ["simple_mopec2.jl"]
Expand Down
2 changes: 1 addition & 1 deletion test/simple_mopec2.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using JuMP, ReSHOP, EMP
using Compat.Test
using Test

@testset "simple mopec" begin

Expand Down

0 comments on commit bcae9ae

Please sign in to comment.