Skip to content

Commit b2343a7

Browse files
committed
Merging hotfixes and dev number
2 parents b1d2ca0 + 6ed5b23 commit b2343a7

9 files changed

+26
-18
lines changed

Diff for: examples/factory_planning_1.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from swat import CAS
21
import sasoptpy as so
32
import pandas as pd
43

Diff for: examples/food_manufacture_1.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from swat import CAS
21
import sasoptpy as so
32
import pandas as pd
43

Diff for: examples/food_manufacture_2.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from swat import CAS
21
import sasoptpy as so
32
import pandas as pd
43

@@ -70,8 +69,8 @@ def test(cas_conn):
7069
# Additions to the first problem
7170
isUsed = m.add_variables(OILS, PERIODS, vartype=so.BIN, name='is_used')
7271
for p in PERIODS:
73-
[use[o, p].set_bounds(ub=veg_ub) for o in VEG]
74-
[use[o, p].set_bounds(ub=nonveg_ub) for o in NONVEG]
72+
use[o, p].set_bounds(ub=veg_ub) for o in VEG
73+
use[o, p].set_bounds(ub=nonveg_ub) for o in NONVEG
7574
m.add_constraints((use[o, p] <= use[o, p]._ub * isUsed[o, p]
7675
for o in OILS for p in PERIODS), name='link')
7776
m.add_constraints((isUsed.sum('*', p) <= max_num_oils_used

Diff for: examples/refinery_optimization.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from swat import CAS
21
import sasoptpy as so
32
import pandas as pd
43
import numpy as np

Diff for: examples/sas_kidney_exchange.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from swat import CAS
21
import sasoptpy as so
32
import random
43

Diff for: sasoptpy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
from sasoptpy.components import *
3030
# from sasoptpy.gui import start_gui
3131

32-
__version__ = '0.1.0'
32+
__version__ = '0.1.1.dev0'

Diff for: sasoptpy/components.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
# limitations under the License.
1717
#
1818

19-
import copy
2019
from itertools import product
2120
from math import copysign, inf
2221
from types import GeneratorType
22+
import warnings
2323

2424
import numpy as np
2525
import pandas as pd
@@ -463,7 +463,7 @@ def __init__(self, name, vartype=sasoptpy.methods.CONT, lb=0, ub=inf):
463463
if vartype == sasoptpy.methods.BIN:
464464
self._lb = max(self._lb, 0)
465465
self._ub = min(self._ub, 1)
466-
self._linCoef = {name: {'ref': self, 'val': 1.0}}
466+
self._linCoef[name] = {'ref': self, 'val': 1.0}
467467
sasoptpy.methods.register_name(name, self)
468468
self._cons = set()
469469
self._key = None
@@ -902,17 +902,22 @@ def __getitem__(self, key):
902902
indices_to_filter = []
903903
filter_values = {}
904904
list_of_variables = []
905-
for i, _ in enumerate(key):
906-
if key[i] != '*':
905+
for i, _ in enumerate(k):
906+
if k[i] != '*':
907907
indices_to_filter.append(i)
908-
filter_values[i] = sasoptpy.methods._list_item(key[i])
908+
filter_values[i] = sasoptpy.methods._list_item(k[i])
909909
for v in self._vardict:
910910
eligible = True
911911
for f in indices_to_filter:
912912
if v[f] not in filter_values[f]:
913913
eligible = False
914914
if eligible:
915915
list_of_variables.append(self._vardict[v])
916+
if not list_of_variables:
917+
warnings.warn('Requested variable group is empty:' +
918+
' {}[{}] ({})'.
919+
format(self._name, key, type(key)),
920+
RuntimeWarning, stacklevel=2)
916921
return list_of_variables
917922

918923
def __iter__(self):
@@ -981,7 +986,7 @@ def mult(self, vector):
981986
Returns
982987
-------
983988
:class:`Expression` object
984-
An expression that is the product of the variable group with the
989+
An expression that is the product of the variable group with the
985990
given vector
986991
987992
Examples
@@ -1131,7 +1136,7 @@ class ConstraintGroup:
11311136
11321137
Notes
11331138
-----
1134-
Use :func:`sasoptpy.Model.add_constraints` when working with a single
1139+
Use :func:`sasoptpy.Model.add_constraints` when working with a single
11351140
model.
11361141
11371142
See also

Diff for: sasoptpy/model.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from math import inf
2626
from time import time
2727
from types import GeneratorType
28+
import warnings
2829

2930
import pandas as pd
3031

@@ -81,6 +82,13 @@ def __init__(self, name, session=None):
8182
sasoptpy.methods.register_name(name, self)
8283
print('NOTE: Initialized model {}'.format(name))
8384

85+
def __eq__(self, other):
86+
if not isinstance(other, sasoptpy.Model):
87+
warnings.warn('Cannot compare Model object with {}'.
88+
format(type(other)), RuntimeWarning, stacklevel=2)
89+
return False
90+
return super().__eq__(other)
91+
8492
def add_variable(self, var=None, vartype=sasoptpy.methods.CONT, name=None,
8593
lb=0, ub=inf):
8694
'''
@@ -378,7 +386,7 @@ def include(self, *argv):
378386
379387
Notes
380388
-----
381-
* This function is essentially a wrapper for two functions,
389+
* This function is essentially a wrapper for two functions,
382390
:func:`sasoptpy.Model.add_variable` and
383391
:func:`sasoptpy.Model.add_constraint`.
384392
* Including a model causes all variables and constraints inside the
@@ -914,7 +922,7 @@ def to_frame(self):
914922
else:
915923
current_row.append(c._name)
916924
current_row.append(rhs)
917-
#self._append_row(['', 'RHS', c._name, rhs, '', ''])
925+
# self._append_row(['', 'RHS', c._name, rhs, '', ''])
918926
f5 = 0
919927
self._append_row(current_row)
920928
if f5 == 1:

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setup(
2424
name='sasoptpy',
25-
version='0.1.0',
25+
version='0.1.1.dev0',
2626
packages=['sasoptpy'],
2727
author='SAS',
2828
author_email='[email protected]',

0 commit comments

Comments
 (0)