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 109 of file alias.py.

References my_assert().

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

◆ gdxdump1()

def alias.gdxdump1 ( )

Definition at line 43 of file alias.py.

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

◆ gdxdump2()

def alias.gdxdump2 ( )

Definition at line 24 of file alias.py.

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

◆ get_data_text()

def alias.get_data_text ( )

Definition at line 83 of file alias.py.

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

◆ my_assert()

def alias.my_assert (   test,
  msg 
)

Definition at line 104 of file alias.py.

Referenced by check_alias_logic().

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

◆ same_gdx_dump()

def alias.same_gdx_dump (   ws,
  gdxfile,
  expected_result 
)

Definition at line 94 of file alias.py.

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

Variable Documentation

◆ aa

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

Definition at line 161 of file alias.py.

◆ aa_orig

alias.aa_orig = db["aa"]

Definition at line 159 of file alias.py.

◆ db

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

Definition at line 150 of file alias.py.

◆ db2

alias.db2 = ws.add_database()

Definition at line 155 of file alias.py.

◆ ii

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

Definition at line 156 of file alias.py.

◆ j1

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

Definition at line 143 of file alias.py.

◆ ws

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

Definition at line 137 of file alias.py.