From ac6c57e1c7adfb5aeed2c3f262dd60497f501d4f Mon Sep 17 00:00:00 2001 From: Azzaare Date: Mon, 22 Mar 2021 15:37:18 +0900 Subject: [PATCH 1/4] Add instances.jl file in test. --- test/instances.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/instances.jl b/test/instances.jl index 973c581..3c27440 100644 --- a/test/instances.jl +++ b/test/instances.jl @@ -40,6 +40,7 @@ qap_distances = [ 4 4 3 3 6 7 6 5 5 7 0 9 6 7 6 6 7 5 7 3 2 7 9 0 ] +<<<<<<< HEAD compounds_names = ["H", "H₂", "H₂O", "N", "N₂", "NH", "NO", "O", "O₂", "OH"] @@ -68,3 +69,5 @@ standard_free_energy = [ -26.662 -22.179 ] +======= +>>>>>>> Add instances.jl file in test. From be05ef17a01e356169751fb5d3706c74ecee3712 Mon Sep 17 00:00:00 2001 From: azzaare Date: Thu, 25 Mar 2021 06:55:37 +0900 Subject: [PATCH 2/4] update CBLS tests --- test/MOI_wrapper.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/MOI_wrapper.jl b/test/MOI_wrapper.jl index ee896b3..623596d 100644 --- a/test/MOI_wrapper.jl +++ b/test/MOI_wrapper.jl @@ -15,11 +15,11 @@ const OPTIMIZER = MOI.instantiate(OPTIMIZER_CONSTRUCTOR) @test MOI.get(OPTIMIZER, MOI.SolverName()) == "LocalSearchSolvers" end -@testset "supports_default_copy_to" begin - @test MOIU.supports_default_copy_to(OPTIMIZER, false) - # Use `@test !...` if names are not supported - @test !MOIU.supports_default_copy_to(OPTIMIZER, true) -end +# @testset "supports_default_copy_to" begin +# @test MOIU.supports_default_copy_to(OPTIMIZER, false) +# # Use `@test !...` if names are not supported +# @test !MOIU.supports_default_copy_to(OPTIMIZER, true) +# end const BRIDGED = MOI.instantiate( OPTIMIZER_CONSTRUCTOR, with_bridge_type = Float64 From 659b510d6c8fc1e81beec79a66026df1cf282770 Mon Sep 17 00:00:00 2001 From: azzaare Date: Thu, 25 Mar 2021 07:08:40 +0900 Subject: [PATCH 3/4] Instance problem commented (temp fix) --- test/instances.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/instances.jl b/test/instances.jl index 3c27440..b2220c4 100644 --- a/test/instances.jl +++ b/test/instances.jl @@ -40,9 +40,8 @@ qap_distances = [ 4 4 3 3 6 7 6 5 5 7 0 9 6 7 6 6 7 5 7 3 2 7 9 0 ] -<<<<<<< HEAD -compounds_names = ["H", "H₂", "H₂O", "N", "N₂", "NH", "NO", "O", "O₂", "OH"] +# compounds_names = ["H", "H₂", "H₂O", "N", "N₂", "NH", "NO", "O", "O₂", "OH"] atoms_compounds = [ 1 0 0 @@ -69,5 +68,3 @@ standard_free_energy = [ -26.662 -22.179 ] -======= ->>>>>>> Add instances.jl file in test. From 86eb4d875d4af8e28a69a7bb2ed94786998c7ce2 Mon Sep 17 00:00:00 2001 From: Azzaare Date: Thu, 25 Mar 2021 18:37:09 +0900 Subject: [PATCH 4/4] Sync with CBLS version. Add Chemical equilibrium --- Project.toml | 2 +- src/assignment.jl | 1 + src/chemical_equilibrium.jl | 19 +++++++++++++++++-- test/instances.jl | 6 ++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index c182c6b..a445ebb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ConstraintModels" uuid = "841a6ec5-cac3-4c42-9a0a-4b21c9553698" authors = ["Jean-Francois Baffier"] -version = "0.1.3" +version = "0.1.4" [deps] CBLS = "a3809bfe-37bb-4d48-a667-bac4c6be8d90" diff --git a/src/assignment.jl b/src/assignment.jl index 56b2876..49eb810 100644 --- a/src/assignment.jl +++ b/src/assignment.jl @@ -5,6 +5,7 @@ function qap(n, W, D, ::Val{:JuMP}) @constraint(model, X in AllDifferent()) Σwd = p -> sum(sum(W[p[i], p[j]] * D[i, j] for j in 1:n) for i in 1:n) + @objective(model, Min, ScalarFunction(Σwd)) return model, X diff --git a/src/chemical_equilibrium.jl b/src/chemical_equilibrium.jl index efb244f..147b948 100644 --- a/src/chemical_equilibrium.jl +++ b/src/chemical_equilibrium.jl @@ -1,8 +1,23 @@ -function chemical_equilibrium(n, A, C) +function chemical_equilibrium(A, B, C) model = JuMP.Model(CBLS.Optimizer) + n = length(C) + m = length(B) + # Add the number of moles per compound (continuous interval) - @variable(model, X[1:n], DiscreteSet(1:n)) + @variable(model, 0 ≤ X[1:n] ≤ maximum(B)) + + # mass_conservation function + conserve = i -> (x -> sum(A[:, i] .* x) == B[i]) + + for i in 1:m + @constraint(model, X in Predicate(conserve(i))) + end + + # computes the total energy freed by the reaction + free_energy = x -> sum(j -> x[j] * (C[j] + log(x[j] / sum(x)))) + + @objective(model, Min, ScalarFunction(free_energy)) return model, X end diff --git a/test/instances.jl b/test/instances.jl index b2220c4..7a744ad 100644 --- a/test/instances.jl +++ b/test/instances.jl @@ -41,8 +41,6 @@ qap_distances = [ 6 7 6 6 7 5 7 3 2 7 9 0 ] -# compounds_names = ["H", "H₂", "H₂O", "N", "N₂", "NH", "NO", "O", "O₂", "OH"] - atoms_compounds = [ 1 0 0 2 0 0 @@ -56,6 +54,8 @@ atoms_compounds = [ 1 0 1 ] +elements_weights = [2 1 1] + standard_free_energy = [ -6.0890 -17.164 @@ -68,3 +68,5 @@ standard_free_energy = [ -26.662 -22.179 ] + +compounds_names = ["H", "H₂", "H₂O", "N", "N₂", "NH", "NO", "O", "O₂", "OH"]