Skip to content

Commit 86eb4d8

Browse files
committed
Sync with CBLS version. Add Chemical equilibrium
1 parent 659b510 commit 86eb4d8

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ConstraintModels"
22
uuid = "841a6ec5-cac3-4c42-9a0a-4b21c9553698"
33
authors = ["Jean-Francois Baffier"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
CBLS = "a3809bfe-37bb-4d48-a667-bac4c6be8d90"

src/assignment.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function qap(n, W, D, ::Val{:JuMP})
55
@constraint(model, X in AllDifferent())
66

77
Σwd = p -> sum(sum(W[p[i], p[j]] * D[i, j] for j in 1:n) for i in 1:n)
8+
89
@objective(model, Min, ScalarFunction(Σwd))
910

1011
return model, X

src/chemical_equilibrium.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
function chemical_equilibrium(n, A, C)
1+
function chemical_equilibrium(A, B, C)
22
model = JuMP.Model(CBLS.Optimizer)
33

4+
n = length(C)
5+
m = length(B)
6+
47
# Add the number of moles per compound (continuous interval)
5-
@variable(model, X[1:n], DiscreteSet(1:n))
8+
@variable(model, 0 X[1:n] maximum(B))
9+
10+
# mass_conservation function
11+
conserve = i -> (x -> sum(A[:, i] .* x) == B[i])
12+
13+
for i in 1:m
14+
@constraint(model, X in Predicate(conserve(i)))
15+
end
16+
17+
# computes the total energy freed by the reaction
18+
free_energy = x -> sum(j -> x[j] * (C[j] + log(x[j] / sum(x))))
19+
20+
@objective(model, Min, ScalarFunction(free_energy))
621

722
return model, X
823
end

test/instances.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ qap_distances = [
4141
6 7 6 6 7 5 7 3 2 7 9 0
4242
]
4343

44-
# compounds_names = ["H", "H₂", "H₂O", "N", "N₂", "NH", "NO", "O", "O₂", "OH"]
45-
4644
atoms_compounds = [
4745
1 0 0
4846
2 0 0
@@ -56,6 +54,8 @@ atoms_compounds = [
5654
1 0 1
5755
]
5856

57+
elements_weights = [2 1 1]
58+
5959
standard_free_energy = [
6060
-6.0890
6161
-17.164
@@ -68,3 +68,5 @@ standard_free_energy = [
6868
-26.662
6969
-22.179
7070
]
71+
72+
compounds_names = ["H", "H₂", "H₂O", "N", "N₂", "NH", "NO", "O", "O₂", "OH"]

0 commit comments

Comments
 (0)