Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

UndefRefError: access to undefined reference #70

Closed
linyuantiaohe opened this issue Oct 5, 2022 · 6 comments
Closed

UndefRefError: access to undefined reference #70

linyuantiaohe opened this issue Oct 5, 2022 · 6 comments

Comments

@linyuantiaohe
Copy link

Where may this error come from? I run the code to solve a MCP on M1 MacBook using rosetta. Could it be the reason?

UndefRefError: access to undefined reference

Stacktrace:
[1] getindex
@ ./array.jl:924 [inlined]
[2] getindex
@ ./abstractarray.jl:1244 [inlined]
[3] _c_constraint_name(id_ptr::Ptr{Nothing}, i::Int32, buf_ptr::Ptr{UInt8}, buf_size::Int32)
@ PATHSolver ~/.julia/packages/PATHSolver/SXBNU/src/C_API.jl:231
[4] c_api_Path_Solve
@ ~/.julia/packages/PATHSolver/SXBNU/src/C_API.jl:512 [inlined]
[5] solve_mcp(F::Complementarity.var"#function_callback#5"{NLPEvaluator}, J::Complementarity.var"#jacobian_callback#7"{Complementarity.var"#j_eval#6"{NLPEvaluator}}, lb::Vector{Float64}, ub::Vector{Float64}, z::Vector{Float64}; nnz::Int64, variable_names::Vector{String}, constraint_names::Vector{String}, silent::Bool, generate_output::Int64, use_start::Bool, use_basics::Bool, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:convergence_tolerance, :output, :time_limit), Tuple{Float64, String, Int64}}})
@ PATHSolver ~/.julia/packages/PATHSolver/SXBNU/src/C_API.jl:626
[6] _solve_path!(m::Model; kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:convergence_tolerance, :output, :time_limit), Tuple{Float64, String, Int64}}})
@ Complementarity ~/.julia/packages/Complementarity/a6hjV/src/mcp.jl:217
[7] solveMCP(m::Model; solver::Symbol, method::Symbol, linear::Bool, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:convergence_tolerance, :output, :time_limit), Tuple{Float64, String, Int64}}})
@ Complementarity ~/.julia/packages/Complementarity/a6hjV/src/mcp.jl:101
[8] top-level scope
@ ~/Mygithub/julia_helloworld/mcp.ipynb:68

@chkwon
Copy link
Owner

chkwon commented Oct 5, 2022

Could you share a minimal working example code that creates this error? Without it, it's hard to tell.

@linyuantiaohe
Copy link
Author

Sure! Here is the whole model code. Thank you!

ee2020_model=MCPModel()
@variable(ee2020_model, 0<= newpg[pg in pg_techs, r in regions] <= TOTAL_PG_CAP[r,pg])
@variable(ee2020_model, pg_s[pg in pg_techs,r in regions,r1 in regions] >= 0)
@variable(ee2020_model, pg_b[pg in pg_techs,r in regions,r1 in regions] >= 0)
@variable(ee2020_model, rec_s[r in regions] >= 0)
@variable(ee2020_model, rec_b[r in regions] >= 0)
@variable(ee2020_model, caq_s[r in regions] >= 0)
@variable(ee2020_model, caq_b[r in regions] >= 0)
@variable(ee2020_model, pri_pg[pg in pg_techs,r in regions,r1 in regions])
@variable(ee2020_model, pri_rec)
@variable(ee2020_model, pri_caq)

@variable(ee2020_model, a_cgoutputmax[pg in pg_techs,r in regions] <= 0)
@variable(ee2020_model, a_selllimit[r in regions,r1 in regions] <= 0)
@variable(ee2020_model, a_capmeet[r in regions] <= 0)
@variable(ee2020_model, a_caqselllimit[r in regions] <= 0)

@variable(ee2020_model, b_demandmeet[r in regions])
@variable(ee2020_model, b_rpsmeet[r in regions] <= 0)
@variable(ee2020_model, b_recselllimit[r in regions] <= 0)

@mapping(ee2020_model, cgoutputmax[pg in pg_techs,r in regions], sum(pg_s[pg,r,r1] for r1 in regions)-(GIC[r,pg]+newpg[pg,r])*GUH[r,pg])
@mapping(ee2020_model, selllimit[r in regions,r1 in regions], sum(pg_s[pg,r,r1] for pg in pg_techs)-TCAP[r,r1]8000)
@mapping(ee2020_model, capmeet[r in regions],caq_s[r]-caq_b[r]-sum(pg_s[pg,r,r1]
(CAP-GEF[pg]) for pg in pg_techs for r1 in regions))
@mapping(ee2020_model, caqselllimit[r in regions],caq_s[r]-sum(pg_s[pg,r,r1]*CAP for pg in pg_techs for r1 in regions))

@mapping(ee2020_model, kkt_newpg[pg in pg_techs,r in regions],drCAPCOST[pg]+a_cgoutputmax[pg,r]GUH[r,pg])
@mapping(ee2020_model, kkt_pg_s[pg in pg_techs,r in regions,r1 in regions],dr
(GVC[pg]-pri_pg[pg,r,r1])-a_cgoutputmax[pg,r]-a_selllimit[r,r1]+a_capmeet[r]
(CAP-GEF[pg])+a_caqselllimit[r]CAP)
@mapping(ee2020_model, kkt_caq_b[r in regions],dr
pri_caq+a_capmeet[r])
@mapping(ee2020_model, kkt_caq_s[r in regions],-dr*pri_caq-a_capmeet[r]-a_caqselllimit[r])

@mapping(ee2020_model,demandmeet[r in regions], sum(pg_b[pg,r,r1]*TEF[r1,r] for pg in pg_techs for r1 in regions)-DEM[r]0)
@mapping(ee2020_model,rpsmeet[r in regions], RPS
DEM[r]+rec_s[r]-sum(pg_b[pg,r,r1]*TEF[r1,r]*CG[pg] for pg in pg_techs for r1 in regions)-rec_b[r])
@mapping(ee2020_model,recselllimit[r in regions],rec_s[r]-sum(pg_b[pg,r,r1]*TEF[r1,r]*CG[pg] for pg in pg_techs for r1 in regions))

@mapping(ee2020_model, kkt_pg_b[pg in pg_techs,r in regions,r1 in regions],dr*(pri_pg[pg,r1,r]+GRIDCOST[r1,r])
-b_demandmeet[r]*TEF[r1,r]+b_rpsmeet[r]*TEF[r1,r]*CG[pg]+b_recselllimit[r]TEF[r1,r]CG[pg])
@mapping(ee2020_model, kkt_rec_b[r in regions],dr
pri_rec+b_rpsmeet[r])
@mapping(ee2020_model, kkt_rec_s[r in regions],-dr
pri_rec-b_rpsmeet[r]-b_recselllimit[r])

@mapping(ee2020_model, mc_pg[pg in pg_techs,r in regions,r1 in regions],pg_s[pg,r,r1]-pg_b[pg,r1,r])
@mapping(ee2020_model, mc_rec,sum(rec_s[r]-rec_b[r] for r in regions))
@mapping(ee2020_model, mc_caq,sum(caq_s[r]-caq_b[r] for r in regions))

@complementarity(ee2020_model, cgoutputmax, a_cgoutputmax)
@complementarity(ee2020_model, selllimit, a_selllimit)
@complementarity(ee2020_model, capmeet, a_capmeet)
@complementarity(ee2020_model, caqselllimit, a_caqselllimit)

@complementarity(ee2020_model, kkt_newpg,newpg)
@complementarity(ee2020_model, kkt_pg_s,pg_s)
@complementarity(ee2020_model, kkt_caq_b,caq_b)
@complementarity(ee2020_model, kkt_caq_s,caq_s)

@complementarity(ee2020_model, demandmeet,b_demandmeet)
@complementarity(ee2020_model, rpsmeet,b_rpsmeet)
@complementarity(ee2020_model, recselllimit,b_recselllimit)

@complementarity(ee2020_model, kkt_pg_b, pg_b)
@complementarity(ee2020_model, kkt_rec_b, rec_b)
@complementarity(ee2020_model, kkt_rec_b, rec_b)

@complementarity(ee2020_model, mc_pg,pri_pg)
@complementarity(ee2020_model, mc_rec,pri_rec)
@complementarity(ee2020_model, mc_caq,pri_caq)

status = solveMCP(ee2020_model, solver=:PATH, convergence_tolerance=1e-8, output="yes", time_limit=3600)

@chkwon
Copy link
Owner

chkwon commented Oct 5, 2022

pg_techs is undefined in your code. Hope you can post a smaller example that I can actually run.

@linyuantiaohe
Copy link
Author

I upload the whole code and data on Github https://github.com/linyuantiaohe/julia_mcp_model_case

Thank you a lot for help. This model can run in GAMS. I rewrite it in Julia, and there comes errors.

@chkwon
Copy link
Owner

chkwon commented Oct 5, 2022

You are repeating this twice:

@complementarity(ee2020_model, kkt_rec_b, rec_b)

One of them should be

@complementarity(ee2020_model, kkt_rec_s, rec_s)

After that, it runs well.

I think your model is linear, isn't it? In such a case, you should better use PATHSolver.jl directly. It is better integrated with JuMP.

@chkwon chkwon closed this as completed Oct 5, 2022
@linyuantiaohe
Copy link
Author

Thank you so much for spending time on my mistake. And thank you for your suggestion, I will try it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants