Skip to content

Commit

Permalink
README.jl updated and example working (node adding order correct)
Browse files Browse the repository at this point in the history
  • Loading branch information
esahon committed Aug 30, 2024
1 parent 3928054 commit 54136a0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ using DecisionProgramming
diagram = InfluenceDiagram()

add_node!(diagram, DecisionNode("A", [], ["a", "b"]))
add_node!(diagram, DecisionNode("D", ["B", "C"], ["k", "l"]))
add_node!(diagram, ChanceNode("B", ["A"], ["x", "y"]))
add_node!(diagram, ChanceNode("C", ["A"], ["v", "w"]))
add_node!(diagram, DecisionNode("D", ["B", "C"], ["k", "l"]))
add_node!(diagram, ValueNode("V", ["D"]))

generate_arcs!(diagram)
Expand Down
27 changes: 0 additions & 27 deletions examples/readme_test.jl

This file was deleted.

32 changes: 2 additions & 30 deletions src/decision_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -434,43 +434,15 @@ end


function factorization_constraints(model::Model, diagram::InfluenceDiagram, name::Name, μ_statevars::Array{VariableRef}, μ_bar_statevars::Array{VariableRef}, z::OrderedDict{Name, DecisionVariable})
#I_j_mapping_in_cluster = [findfirst(isequal(node), diagram.RJT.clusters[name]) for node in diagram.I_j[name]] # Map the information set to the variables in the cluster
I_j_mapping_in_cluster = [findfirst(isequal(node), diagram.RJT.clusters[name]) for node in diagram.I_j[name]]
I_j_states_mapping_in_cluster = similar(I_j_mapping_in_cluster)
for node_index in 1:length(I_j_states_mapping_in_cluster)
I_j_states_mapping_in_cluster[node_index] = diagram.S[diagram.RJT.clusters[name][node_index]]
end
#println("kokeilu:")
#println(I_j_mapping_in_cluster)
#println(I_j_states_mapping_in_cluster)
#println("")
I_j_mapping_in_cluster = [findfirst(isequal(node), diagram.RJT.clusters[name]) for node in diagram.I_j[name]] # Map the information set to the variables in the cluster
for index in CartesianIndices(μ_bar_statevars)
for s_j in 1:length(diagram.States[name])
#println(s_j)
#println(Tuple(index)[I_j_states_mapping_in_cluster]...,s_j)
#println(diagram.X[name])
#println(typeof(diagram.X[name]))
if isa(diagram.Nodes[name], ChanceNode)
# μ_{C_v} = μ_{\bar{C}_v}*p
@constraint(model, μ_statevars[Tuple(index)...,s_j] == diagram.X[name][Tuple(index)[I_j_mapping_in_cluster]...,s_j]*μ_bar_statevars[index])
elseif isa(diagram.Nodes[name], DecisionNode)
# μ_{C_v} ≤ z

#println(index)
#println(typeof(index))
#println(I_j_states_mapping_in_cluster)
#println(s_j)
#println(z[name])
#println(z[name].z)
#if I_j_mapping_in_cluster ==[2, 3]
# println(z[name].z[1, 1, 1])
#end
#println([I_j_states_mapping_in_cluster]...,s_j)
#println(Tuple(index)[I_j_states_mapping_in_cluster]...,s_j)
#println(z[name].z[Tuple(index)[I_j_states_mapping_in_cluster]...,s_j])
#println("")

@constraint(model, μ_statevars[Tuple(index)...,s_j] <= z[name].z[Tuple(index)[I_j_states_mapping_in_cluster]...,s_j])
@constraint(model, μ_statevars[Tuple(index)...,s_j] <= z[name].z[Tuple(index)[I_j_mapping_in_cluster]...,s_j])
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions src/influence_diagram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ function validate_node(diagram::InfluenceDiagram,
@warn("Value node $name is redundant.")
end
end

if !all([haskey(diagram.Nodes, name) for name in I_j])
throw(DomainError("The nodes in the information set of node $name should be added before $name."))
end
end

"""
Expand Down

0 comments on commit 54136a0

Please sign in to comment.