alias Namespace Reference

Functions

def gdxdump2 ()
 
def gdxdump1 ()
 
def get_data_text ()
 
def same_gdx_dump (ws, gdxfile, expected_result)
 
def my_assert (test, msg)
 
def check_alias_logic (prefix, alias_db)
 

Variables

 ws = GamsWorkspace(system_directory = sys.argv[1])
 
 j1 = ws.add_job_from_string(get_data_text())
 
 db = ws.add_database(source_database= j1.out_db)
 
 db2 = ws.add_database()
 
 ii = db2.add_set_dc(db["ii"].name, ["*"], db["ii"].text)
 
 aa_orig = db["aa"]
 
 aa = db2.add_parameter_dc(db["aa"].name, [ii], db["aa"].text, )
 

Function Documentation

◆ check_alias_logic()

def alias.check_alias_logic (   prefix,
  alias_db 
)

Definition at line 108 of file alias.py.

References my_assert().

108def check_alias_logic(prefix, alias_db):
109 # Check number of symbols
110 my_assert(len(alias_db) == 5, prefix + "alias_db should have NrSymbols=5: i,j,ij,a,aa.")
111
112 cnt_symbols = 0
113 for sym in alias_db:
114 cnt_symbols += 1
115 my_assert(cnt_symbols == 5, prefix + "'for sym in alias_db' should result in 5 symbols: i,j,ij,a,aa.")
116
117 # See if we can retrieve alias sets
118 my_assert(alias_db["ii"].name == "i", prefix + "We should get set i when asking for alias ii.")
119 my_assert(alias_db["jj"].name == "j", prefix + "We should get set j when asking for alias jj.")
120 my_assert(alias_db["iijj"].name == "ij", prefix + "We should get set ij when asking for alias iijj.")
121
122 # Check domain logic
123 my_assert(alias_db.check_domains() == True, prefix + "Check domains should be true")
124 my_assert(type(alias_db["aa"].domains[0]) is GamsSet, prefix + "domain[0] of aa should be set")
125 my_assert((alias_db["aa"].domains[0]).name == "i", prefix + "domain[0] of aa should point to i")
126
127 alias_db["ii"].delete_record("i1")
128 my_assert(alias_db.check_domains() == False, prefix + "Check domains should be false after removal of i1")
129 alias_db["ii"].add_record("i1")
130 my_assert(alias_db.check_domains() == True, prefix + "Check domains should be true after adding i1 again")
131
132
def check_alias_logic(prefix, alias_db)
Definition: alias.py:108
def my_assert(test, msg)
Definition: alias.py:103

◆ gdxdump1()

def alias.gdxdump1 ( )

Definition at line 42 of file alias.py.

42def gdxdump1():
43 data = '''
44$onempty
45
46Set i(*) /
47'i1',
48'i2',
49'i3' /;
50
51Set j(*) /
52'j1',
53'j2',
54'j3' /;
55
56Set ij(*,*) /
57'i1'.'j1',
58'i2'.'j2',
59'i3'.'j3' /;
60
61Alias (ii, i);
62
63Alias (jj, j);
64
65Alias (iijj, ij);
66
67Parameter a(i) /
68'i1' 1,
69'i2' 1,
70'i3' 1 /;
71
72Parameter aa(ii) /
73'i1' 2,
74'i2' 2,
75'i3' 2 /;
76
77$offempty
78'''
79 return re.sub( '\s', '', data)
80
81
def gdxdump1()
Definition: alias.py:42

◆ gdxdump2()

def alias.gdxdump2 ( )

Definition at line 23 of file alias.py.

23def gdxdump2():
24 data = '''
25$onempty
26
27Set i(*) /
28'i1',
29'i2',
30'i3' /;
31
32Parameter aa(i) /
33'i1' 2,
34'i2' 2,
35'i3' 2 /;
36
37$offempty
38'''
39 return re.sub( '\s', '', data)
40
41
def gdxdump2()
Definition: alias.py:23

◆ get_data_text()

def alias.get_data_text ( )

Definition at line 82 of file alias.py.

82def get_data_text():
83 return '''
84set i / i1*i3 /
85 j / j1*j3 /
86 ij / #i:#j /
87alias (i,ii), (j,jj), (ij,iijj);
88parameter
89 a(i) / #i 1 /, aa(ii) / #ii 2 /;
90'''
91
92
def get_data_text()
Definition: alias.py:82

◆ my_assert()

def alias.my_assert (   test,
  msg 
)

Definition at line 103 of file alias.py.

Referenced by check_alias_logic().

103def my_assert(test, msg):
104 if not test:
105 raise Exception(msg)
106
107
def my_assert(test, msg)
Definition: alias.py:103

◆ same_gdx_dump()

def alias.same_gdx_dump (   ws,
  gdxfile,
  expected_result 
)

Definition at line 93 of file alias.py.

93def same_gdx_dump(ws, gdxfile, expected_result):
94 result = ""
95
96 cmd = [os.path.join(ws.system_directory, "gdxdump"), os.path.join(ws.working_directory, gdxfile)]
97 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
98 result, err = p.communicate()
99 result = re.sub( '\s', '', result.decode())
100 return result.lower() == expected_result.lower()
101
102
def same_gdx_dump(ws, gdxfile, expected_result)
Definition: alias.py:93

Variable Documentation

◆ aa

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

Definition at line 160 of file alias.py.

◆ aa_orig

alias.aa_orig = db["aa"]

Definition at line 158 of file alias.py.

◆ db

alias.db = ws.add_database(source_database= j1.out_db)

Definition at line 149 of file alias.py.

◆ db2

alias.db2 = ws.add_database()

Definition at line 154 of file alias.py.

◆ ii

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

Definition at line 155 of file alias.py.

◆ j1

alias.j1 = ws.add_job_from_string(get_data_text())

Definition at line 142 of file alias.py.

◆ ws

alias.ws = GamsWorkspace(system_directory = sys.argv[1])

Definition at line 136 of file alias.py.