mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
Implement parse_name
This commit is contained in:
@@ -29,6 +29,7 @@ include("solvers/jump_solver.jl")
|
|||||||
include("solvers/learning_solver.jl")
|
include("solvers/learning_solver.jl")
|
||||||
include("solvers/macros.jl")
|
include("solvers/macros.jl")
|
||||||
include("utils/benchmark.jl")
|
include("utils/benchmark.jl")
|
||||||
|
include("utils/parse.jl")
|
||||||
|
|
||||||
function __init__()
|
function __init__()
|
||||||
copy!(miplearn, pyimport("miplearn"))
|
copy!(miplearn, pyimport("miplearn"))
|
||||||
|
|||||||
20
src/utils/parse.jl
Normal file
20
src/utils/parse.jl
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
|
||||||
|
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
function parse_name(name::AbstractString)::Vector{String}
|
||||||
|
# x
|
||||||
|
m = match(r"^[-a-z0-9_]*$", name)
|
||||||
|
if m !== nothing
|
||||||
|
return [name]
|
||||||
|
end
|
||||||
|
|
||||||
|
# x[1,2,3]
|
||||||
|
m = match(r"^([-a-z0-9_]*)\[([-a-z0-9_,]*)\]$"i, name)
|
||||||
|
if m !== nothing
|
||||||
|
return [m[1], split(m[2], ",")...]
|
||||||
|
end
|
||||||
|
|
||||||
|
# unknown
|
||||||
|
error("Could not parse: $(name)")
|
||||||
|
end
|
||||||
12
test/utils/parse_test.jl
Normal file
12
test/utils/parse_test.jl
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
|
||||||
|
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
using MIPLearn
|
||||||
|
|
||||||
|
@testset "Parse" begin
|
||||||
|
@test MIPLearn.parse_name("x") == ["x"]
|
||||||
|
@test MIPLearn.parse_name("x[3]") == ["x", "3"]
|
||||||
|
@test MIPLearn.parse_name("test_eq[x]") == ["test_eq", "x"]
|
||||||
|
@test MIPLearn.parse_name("test_eq[x,y,z]") == ["test_eq", "x", "y", "z"]
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user