Loading...
Searching...
No Matches
alias Namespace Reference

Functions

def same_gdx_dump (ws, gdxfile, expected_result)
 
def check_alias_logic (prefix, db)
 

Variables

str GDX_DUMP2
 
str GDX_DUMP1
 
str GAMS_DATA
 
sys sys_dir = sys.argv[1] if len(sys.argv) > 1 else None
 
GamsWorkspace ws = GamsWorkspace(system_directory=sys_dir)
 
GamsWorkspace job = ws.add_job_from_string(GAMS_DATA)
 
GamsWorkspace db = ws.add_database(source_database=job.out_db)
 
GamsWorkspace db2 = ws.add_database()
 
GamsWorkspace ii = db2.add_set_dc(db["ii"].name, ["*"], db["ii"].text)
 
GamsWorkspace aa_orig = db["aa"]
 
GamsWorkspace aa = db2.add_parameter_dc(db["aa"].name, [ii], db["aa"].text)
 

Function Documentation

◆ check_alias_logic()

def alias.check_alias_logic (   prefix,
  db 
)

Definition at line 109 of file alias.py.

109def check_alias_logic(prefix, db):
110 # check number of symbols
111 if len(db) != 5:
112 raise Exception(
113 f"GamsDatabase '{prefix}' should have five symbols: i, j, ij, a, aa."
114 )
115
116 # check retrival of alias sets
117 if db["ii"].name != "i":
118 raise Exception(f"{prefix}: We should get set 'i' when asking for alias 'ii'.")
119 if db["jj"].name != "j":
120 raise Exception(f"{prefix}: We should get set 'j' when asking for alias 'jj'.")
121 if db["iijj"].name != "ij":
122 raise Exception(
123 f"{prefix}: We should get set 'ij' when asking for alias 'iijj'."
124 )
125
126 # check domain logic
127 if not db.check_domains():
128 raise Exception(f"{prefix}: Check domains should be true.")
129 if not isinstance(db["aa"].domains[0], GamsSet):
130 raise Exception(f"{prefix}: domains[0] of 'aa' should be a set.")
131 if db["aa"].domains[0].name != "i":
132 raise Exception(f"{prefix}: domains[0] of 'aa' should be 'i'.")
133
134 db["ii"].delete_record("i1")
135 if db.check_domains():
136 raise Exception(
137 f"{prefix}: check_domains() should be False after removal of 'i1'."
138 )
139 db["ii"].add_record("i1")
140 if not db.check_domains():
141 raise Exception(
142 f"{prefix}: check_domains() should be True after adding 'i1' again."
143 )
144
145

◆ same_gdx_dump()

def alias.same_gdx_dump (   ws,
  gdxfile,
  expected_result 
)

Definition at line 91 of file alias.py.

91def same_gdx_dump(ws, gdxfile, expected_result):
92 result = ""
93 cmd = [
94 os.path.join(ws.system_directory, "gdxdump"),
95 os.path.join(ws.working_directory, gdxfile),
96 ]
97 p = subprocess.Popen(
98 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE
99 )
100 result, error = p.communicate()
101 if error:
102 raise Exception(error)
103 result = result.decode()
104 return re.sub(r"\s", "", result.lower()) == re.sub(
105 r"\s", "", expected_result.lower()
106 )
107
108

Variable Documentation

◆ aa

GamsWorkspace alias.aa = db2.add_parameter_dc(db["aa"].name, [ii], db["aa"].text)

Definition at line 170 of file alias.py.

◆ aa_orig

GamsWorkspace alias.aa_orig = db["aa"]

Definition at line 169 of file alias.py.

◆ db

GamsWorkspace alias.db = ws.add_database(source_database=job.out_db)

Definition at line 160 of file alias.py.

◆ db2

GamsWorkspace alias.db2 = ws.add_database()

Definition at line 165 of file alias.py.

◆ GAMS_DATA

str alias.GAMS_DATA
Initial value:
1= """
2Set
3 i / i1*i3 /
4 j / j1*j3 /
5 ij / #i:#j /;
6
7Alias
8 (i,ii)
9 (j,jj)
10 (ij,iijj);
11
12Parameter
13 a(i) / #i 1 /
14 aa(ii) / #ii 2 /;
15"""

Definition at line 74 of file alias.py.

◆ GDX_DUMP1

str alias.GDX_DUMP1

Definition at line 37 of file alias.py.

◆ GDX_DUMP2

str alias.GDX_DUMP2
Initial value:
1= """
2$onempty
3
4Set i(*) /
5'i1',
6'i2',
7'i3' /;
8
9Parameter aa(i) /
10'i1' 2,
11'i2' 2,
12'i3' 2 /;
13
14$offempty
15"""

Definition at line 21 of file alias.py.

◆ ii

GamsWorkspace alias.ii = db2.add_set_dc(db["ii"].name, ["*"], db["ii"].text)

Definition at line 166 of file alias.py.

◆ job

GamsWorkspace alias.job = ws.add_job_from_string(GAMS_DATA)

Definition at line 152 of file alias.py.

◆ sys_dir

sys alias.sys_dir = sys.argv[1] if len(sys.argv) > 1 else None

Definition at line 147 of file alias.py.

◆ ws

GamsWorkspace alias.ws = GamsWorkspace(system_directory=sys_dir)

Definition at line 148 of file alias.py.