Skip to content

Commit

Permalink
Merge pull request #10 from mitchphillipson/masking
Browse files Browse the repository at this point in the history
Sparse parameters and masking
  • Loading branch information
mitchphillipson authored Jan 17, 2024
2 parents 36b9883 + 418d7b8 commit 4063756
Show file tree
Hide file tree
Showing 18 changed files with 536 additions and 270 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ docs/site/
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml


testing_ground/
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
[Very terse documentation](https://mitchphillipson.github.io/GamsStructure.jl/dev/)


2024-01-17

To Do:

1. Speed up indexing on parameters. Currently it is ~3-4x slower than NamedArrays
2. Documentation. Needs massive updating
3. Tests. Need more and more comprehensive
4. Lots of places call field names rather than with a function. Needs changing.


History:

To Do:

1. Deprecate and remove GamsScalars.
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ makedocs(
# assets = ["assets/extra_styles.css"],
# sidebar_sitename = false,
#),
strict = true,
#strict = true,
pages = _PAGES
)

Expand Down
10 changes: 5 additions & 5 deletions docs/src/parameters.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Parameters

```@docs
GamsParameter
Parameter
@parameter
@parameters
load_parameter(GU::GamsUniverse,
path_to_parameter::String,
domain::Tuple{Vararg{Symbol}};
Expand All @@ -17,7 +19,5 @@ load_parameter!(GU::GamsUniverse,
columns::Union{Vector{Int},Missing} = missing,
value_name = :value
)
@load_parameters!(GU,base_path,block)
@create_parameters(GU,block)
domain(P::GamsParameter)
```
```

2 changes: 1 addition & 1 deletion docs/src/sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GamsSet(e::Tuple;description = "")
GamsSet(x::Vector{Tuple{Symbol,String}};description = "")
GamsSet(e::Vector{Symbol};description = "")
GamsDomainSet(base_path::String,parm_name::Symbol,column::Int;description = "")
@create_set!
@set
load_set
load_set!
@load_sets!
Expand Down
119 changes: 0 additions & 119 deletions src/GamsParameter.jl

This file was deleted.

15 changes: 6 additions & 9 deletions src/GamsSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,17 @@ function Base.in(x::GamsElement,r::GamsSet)
end


function Base.getindex(X::GamsSet,i::Symbol)
#for elm in X.elements
# if elm.name == i
# return elm
# end
#end
function Base.getindex(X::GamsSet,i::Int)
return X.elements[i]
end


function Base.getindex(X::GamsSet,i::Symbol)
try
return X.elements[X.index[i]]
return X[X.index[i]]
catch
error("$i is not a member of this set")
end


end

function Base.getindex(X::GamsSet,i::GamsSet)
Expand Down
17 changes: 13 additions & 4 deletions src/GamsStructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ using HDF5

export GamsElement


export GamsSet, alias,@create_set!,@GamsDomainSets,GamsDomainSet,
load_set,load_set!,@load_sets!,deactivate,activate
load_set,load_set!,@load_sets!,deactivate,activate,
@set

export GamsParameter,@create_parameters,
export Parameter,@parameter,@parameters,
load_parameter,load_parameter!,@load_parameters!,domain

export Mask

export GamsUniverse,add_set,add_parameter,unload,load_universe,
load_universe!,sets,parameters


export @extract_sets_as_vector,@extract, @alias


#GamsScalar,
# @GamsScalars
#add_scalar,scalar,
Expand All @@ -30,11 +35,15 @@ export GamsUniverse,add_set,add_parameter,unload,load_universe,


include("structs.jl")
include("dense_sparse.jl")
include("parameter.jl")
include("GamsUniverse.jl")
include("GamsSet.jl")
include("GamsParameter.jl")
#include("GamsParameter.jl")
#include("GamsScalar.jl")

include("macros.jl")

include("io/unload.jl")
include("io/load.jl")
include("io/macros.jl")
Expand Down
23 changes: 12 additions & 11 deletions src/GamsUniverse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ function add_set(GU::GamsUniverse,set_name::Symbol,set::GamsSet)
GU.sets[set_name] = set
end

function add_parameter(GU::GamsUniverse,parm_name::Symbol,parameter::GamsParameter)
function add_parameter(GU::GamsUniverse,parm_name::Symbol,parameter::Parameter)
GU.parameters[parm_name] = parameter
end


function alias(GU::GamsUniverse,base_set::Symbol,aliases...)
for alias in aliases
new_set = deepcopy(GU[base_set])
push!(new_set.aliases,base_set)
for al in new_set.aliases
push!(GU[al].aliases,alias)
end
add_set(GU,alias,new_set)
function alias(GU::GamsUniverse,base_set::Symbol,alias::Symbol)
#for alias in aliases
new_set = deepcopy(GU[base_set])
push!(new_set.aliases,base_set)
for al in new_set.aliases
push!(GU[al].aliases,alias)
end
add_set(GU,alias,new_set)
return new_set

end

function sets(GU::GamsUniverse)
Expand Down Expand Up @@ -50,7 +51,7 @@ function Base.show(io::IO, GU::GamsUniverse)
end
out *= "\nParameters\n\n"
for (key,parm) in GU.parameters
out *= "$key => $(parm.sets) => $(parm.description)\n"
out *= "$key => $(parm.domain) => $(parm.description)\n"
end

return print(io,out)
Expand All @@ -59,6 +60,6 @@ function Base.show(io::IO, GU::GamsUniverse)

end

function Base.setindex!(GU::GamsUniverse,parm::GamsParameter,key::Symbol)
function Base.setindex!(GU::GamsUniverse,parm::Parameter,key::Symbol)
GU.parameters[key] = deepcopy(parm)
end
Loading

0 comments on commit 4063756

Please sign in to comment.