Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gboml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
smart_grids
public
gboml
Commits
a3dc23cd
Commit
a3dc23cd
authored
1 year ago
by
Derval Guillaume
Browse files
Options
Downloads
Patches
Plain Diff
Add variable bounds
parent
34a63f23
No related branches found
No related tags found
No related merge requests found
Pipeline
#15462
failed
1 year ago
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/gboml/ast/variables.py
+3
-0
3 additions, 0 deletions
src/gboml/ast/variables.py
src/gboml/gboml.lark
+1
-1
1 addition, 1 deletion
src/gboml/gboml.lark
src/gboml/parsing.py
+4
-3
4 additions, 3 deletions
src/gboml/parsing.py
with
8 additions
and
4 deletions
src/gboml/ast/variables.py
+
3
−
0
View file @
a3dc23cd
...
...
@@ -2,6 +2,7 @@ from dataclasses import dataclass, field
from
enum
import
Enum
from
typing
import
Optional
from
gboml.ast.expressions
import
Expression
from
gboml.ast.functions
import
Function
from
gboml.ast.arrays
import
Array
,
Range
from
gboml.ast.base
import
GBOMLObject
,
NamedGBOMLObject
...
...
@@ -57,6 +58,8 @@ class VariableDefinition(NamedGBOMLObject):
indices
:
list
[
str
]
scope
:
VarScope
type
:
VarType
bound_lower
:
Optional
[
Expression
]
bound_upper
:
Optional
[
Expression
]
import_from
:
Optional
[
VarOrParam
]
=
None
tags
:
set
[
str
]
=
field
(
default_factory
=
set
)
...
...
This diff is collapsed.
Click to expand it.
src/gboml/gboml.lark
+
1
−
1
View file @
a3dc23cd
...
...
@@ -64,7 +64,7 @@ hyperedge_import: "#HYPEREDGE" ID "=" "import" var_or_param "from" STRING hypere
hyperedge_redefs: "with" definition* | ";"
// VARIABLES
variable_definition: SCOPE [VTYPE] ":" separated_list{variable_name,","} [_LARROW separated_list{var_or_param, ","}] tags ";"
variable_definition: SCOPE [VTYPE] ":" separated_list{variable_name,","} [_LARROW separated_list{var_or_param, ","}]
["in" "[" [expression] ":" [expression] "]"]
tags ";"
variable_name: ID olist{index}
SCOPE: "internal" | "external"
VTYPE: "binary" | "continuous" | "integer"
...
...
This diff is collapsed.
Click to expand it.
src/gboml/parsing.py
+
4
−
3
View file @
a3dc23cd
...
...
@@ -193,12 +193,14 @@ def _lark_to_gboml(tree: Tree, filename: Optional[str] = None) -> GBOMLGraph:
return
GBOMLGraph
(
time_horizon
,
global_defs
,
nodes_hyperedges
.
nodes
,
nodes_hyperedges
.
hyperedges
,
meta
=
meta
)
def
variable_definition
(
self
,
meta
:
Meta
,
scope
:
VarScope
,
type
:
Optional
[
VarType
],
names
:
list
[(
str
,
list
[
str
])],
imports_from
:
Optional
[
list
[
VarOrParam
]],
tags
:
set
[
str
]):
imports_from
:
Optional
[
list
[
VarOrParam
]],
bound_lower
:
Optional
[
Expression
],
bound_upper
:
Optional
[
Expression
],
tags
:
set
[
str
]):
if
imports_from
is
not
None
and
len
(
imports_from
)
!=
len
(
names
):
raise
Exception
(
"
Invalid variable import, numbers of variables on the left and on the right-side of
"
"
`<-` don
'
t match
"
)
for
name
,
import_from
in
zip
(
names
,
imports_from
or
repeat
(
None
,
len
(
names
))):
yield
VariableDefinition
(
name
[
0
],
name
[
1
],
scope
,
type
or
VarType
.
continuous
,
import_from
,
tags
,
meta
=
meta
)
yield
VariableDefinition
(
name
[
0
],
name
[
1
],
scope
,
type
or
VarType
.
continuous
,
bound_lower
,
bound_upper
,
import_from
,
tags
,
meta
=
meta
)
def
variables_block
(
self
,
_
:
Meta
,
*
defs
:
Tuple
[
Iterable
[
VariableDefinition
]]):
return
[
vd
for
iterable
in
defs
for
vd
in
iterable
]
...
...
@@ -223,5 +225,4 @@ def _lark_to_gboml(tree: Tree, filename: Optional[str] = None) -> GBOMLGraph:
else
:
return
ConstantDefinition
(
name
,
val
,
tags
,
meta
=
meta
)
return
GBOMLLarkTransformer
().
transform
(
tree
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment