Skip to content

Commit f74e132

Browse files
committed
Merging changes for new version
2 parents b2343a7 + 2bcac72 commit f74e132

23 files changed

+552
-300
lines changed

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ Model: [
7777
y + 3.0 * x <= 5.5
7878
]
7979
]
80-
NOTE: Converting model demo to data frame
80+
NOTE: Converting model demo to DataFrame
8181
NOTE: Added action set 'optimization'.
82-
NOTE: Uploading the problem data frame to the server.
82+
NOTE: Uploading the problem DataFrame to the server.
8383
NOTE: Cloud Analytic Services made the uploaded file available as table TMPLZLOW3J0 in caslib CASUSERHDFS(casuser).
8484
NOTE: The table TMPLZLOW3J0 has been created in caslib CASUSERHDFS(casuser) from binary data uploaded to Cloud Analytic Services.
8585
NOTE: The problem demo has 2 variables (0 binary, 1 integer, 0 free, 0 fixed).
@@ -101,10 +101,6 @@ NOTE: The Branch and Cut algorithm is using up to 32 threads.
101101
NOTE: Optimal.
102102
NOTE: Objective = 4.
103103
NOTE: Data length = 18 rows
104-
NOTE: Conversion to MPS = 0.0010 secs
105-
NOTE: Upload to CAS time = 0.1344 secs
106-
NOTE: Solution parse time = 0.2669 secs
107-
NOTE: Server solve time = 1.0903 secs
108104
NOTE: Cloud Analytic Services dropped table TMPLZLOW3J0 from caslib CASUSERHDFS(casuser).
109105
Problem Summary
110106

doc/conf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@
5959

6060
# General information about the project.
6161
project = 'sasoptpy'
62-
copyright = '2017, SAS'
63-
author = 'SAS (Sertalp B. Cay)'
62+
copyright = '2017-2018, SAS Institute'
63+
author = 'SAS Institute (Sertalp B. Cay)'
6464

6565
# The version info for the project you're documenting, acts as replacement for
6666
# |version| and |release|, also used in various other places throughout the
6767
# built documents.
6868
#
6969
# The short X.Y version.
70-
version = '0.1.0'
70+
version = '0.1.1.dev0'
7171
# The full version, including alpha/beta/rc tags.
72-
release = '0.1.0'
72+
release = '0.1.1.dev0'
7373

7474
# The language for content autogenerated by Sphinx. Refer to documentation
7575
# for a list of supported languages.

doc/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
sasoptpy: SAS Viya Optimization Interface for Python
44
****************************************************
55

6-
`PDF Version <../latex/sasoptpy.pdf>`_
6+
`PDF Version <sasoptpy.pdf>`_
77

88
.. module:: sasoptpy
99

doc/makedocs.sh

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ make latex
66
sed -i -- 's/CASUSERHDFS([A-Za-z0-9]*)/CASUSERHDFS(casuser)/g' _build/latex/sasoptpy.tex
77
cd _build/latex
88
make
9+
cp sasoptpy.pdf ../html

doc/models.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Linear Optimization) is determined based on variable types.
122122

123123
>>> m.solve()
124124
NOTE: Initialized model model_1
125-
NOTE: Converting model model_1 to data frame
125+
NOTE: Converting model model_1 to DataFrame
126126
NOTE: Added action set 'optimization'.
127127
...
128128
NOTE: Optimal.

doc/sasoptpy.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Classes
2323
ConstraintGroup
2424

2525

26-
Methods
27-
=======
26+
Functions
27+
=========
2828

2929
.. autosummary::
3030
:toctree: generated/
@@ -39,6 +39,7 @@ Methods
3939
get_solution_table
4040
list_length
4141
print_model_mps
42+
quick_sum
4243
read_frame
4344
register_name
4445
reset_globals

doc/whatsnew.rst

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
11

2+
.. currentmodule:: sasoptpy
3+
4+
.. _whatsnew:
5+
6+
27
What's New
38
**********
49

510
This page outlines changes from each release.
611

12+
v0.1.1 (TBD)
13+
============
14+
15+
New Features
16+
++++++++++++
17+
18+
- Initial value argument 'init' is added for :class:`Variable` objects
19+
- :func:`Variable.set_init` method is added for variables
20+
- Initial value option 'primalin' is added to :func:`Model.solve` method
21+
- Table name argument 'name', table drop option 'drop' and replace
22+
option 'replace' are added to :func:`Model.solve` method
23+
- Decomposition block implementation is rewritten, block numbers does
24+
not need to be consecutive and ordered :func:`Model.upload_user_blocks`
25+
- :func:`VariableGroup.get_name` and :func:`ConstraintGroup.get_name` methods
26+
are added
27+
- :func:`Model.test_session` method is added for checking if session is defined
28+
for models
29+
- :func:`quick_sum` function is added for faster summation of
30+
:class:`Expression` objects
31+
32+
Changes
33+
+++++++
34+
35+
- methods.py is renamed to utils.py
36+
37+
Bug Fixes
38+
+++++++++
39+
40+
- Fixed: Crash in VG and CG when a key not in the list is called
41+
- Fixed: get_value of pandas is depreceated
42+
- Fixed: Variables can be set as temporary expressions
43+
- Fixed: Ordering in :func:`get_solution_table` is incorrect for multiple entries
44+
745
v0.1.0 (December 22, 2017)
846
==========================
947

1048
- Initial release
11-

examples/economic_planning.py

+23-22
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

@@ -38,22 +37,24 @@ def test(cas_conn):
3837
INDUSTRIES = industry_data.index.tolist()
3938
[init_stocks, init_productive_capacity, demand] = so.read_frame(
4039
industry_data)
41-
INPUTS = production_data.index.tolist()
40+
# INPUTS = production_data.index.tolist()
4241
production_coeff = so.flatten_frame(production_data)
4342
productive_capacity_coeff = so.flatten_frame(productive_capacity_data)
4443

4544
static_production = m.add_variables(INDUSTRIES, lb=0,
4645
name='static_production')
4746
m.set_objective(0, sense=so.MIN, name='Zero')
4847
m.add_constraints((static_production[i] == demand[i] +
49-
sum(production_coeff[i, j] * static_production[j]
48+
so.quick_sum(
49+
production_coeff[i, j] * static_production[j]
5050
for j in INDUSTRIES) for i in INDUSTRIES),
5151
name='static_con')
5252

5353
m.solve()
5454
print(so.get_solution_table(static_production))
5555

56-
final_demand = so.get_solution_table(static_production)['static_production']
56+
final_demand = so.get_solution_table(
57+
static_production)['static_production']
5758
# Alternative way
5859
# final_demand = {}
5960
# for i in INDUSTRIES:
@@ -69,35 +70,35 @@ def test(cas_conn):
6970
for i in INDUSTRIES:
7071
for year in range(1, num_years+2):
7172
productive_capacity[i, year] = init_productive_capacity[i] +\
72-
sum(extra_capacity[i, y] for y in range(2, year+1))
73+
so.quick_sum(extra_capacity[i, y] for y in range(2, year+1))
7374
for i in INDUSTRIES:
7475
production[i, 0].set_bounds(ub=0)
7576
stock[i, 0].set_bounds(lb=init_stocks[i], ub=init_stocks[i])
7677

7778
total_productive_capacity = sum(productive_capacity[i, num_years]
7879
for i in INDUSTRIES)
79-
total_production = sum(production[i, year] for i in INDUSTRIES
80-
for year in [4, 5])
81-
total_manpower = sum(production_coeff['manpower', i] *
82-
production[i, year+1] +
83-
productive_capacity_coeff['manpower', i] *
84-
extra_capacity[i, year+2]
85-
for i in INDUSTRIES for year in YEARS)
80+
total_production = so.quick_sum(production[i, year] for i in INDUSTRIES
81+
for year in [4, 5])
82+
total_manpower = so.quick_sum(production_coeff['manpower', i] *
83+
production[i, year+1] +
84+
productive_capacity_coeff['manpower', i] *
85+
extra_capacity[i, year+2]
86+
for i in INDUSTRIES for year in YEARS)
8687

8788
continuity_con = m.add_constraints((
8889
stock[i, year] + production[i, year] ==
8990
(demand[i] if year in YEARS else 0) +
90-
sum(production_coeff[i, j] * production[j, year+1] +
91-
productive_capacity_coeff[i, j] * extra_capacity[j, year+2]
92-
for j in INDUSTRIES) +
91+
so.quick_sum(production_coeff[i, j] * production[j, year+1] +
92+
productive_capacity_coeff[i, j] *
93+
extra_capacity[j, year+2] for j in INDUSTRIES) +
9394
stock[i, year+1]
9495
for i in INDUSTRIES for year in YEARS0), name='continuity_con')
9596

9697
manpower_con = m.add_constraints((
97-
sum(production_coeff['manpower', j] * production[j, year] +
98-
productive_capacity_coeff['manpower', j] *
99-
extra_capacity[j, year+1]
100-
for j in INDUSTRIES)
98+
so.quick_sum(production_coeff['manpower', j] * production[j, year] +
99+
productive_capacity_coeff['manpower', j] *
100+
extra_capacity[j, year+1]
101+
for j in INDUSTRIES)
101102
<= manpower_capacity for year in range(1, num_years+2)),
102103
name='manpower_con')
103104

@@ -137,7 +138,7 @@ def test(cas_conn):
137138
continuity_con[i, year].set_rhs(0)
138139
problem2.solve()
139140
print(so.get_solution_table(production, stock, extra_capacity,
140-
productive_capacity))
141+
productive_capacity))
141142
print(so.get_solution_table(manpower_con.get_expressions()))
142143

143144
# Problem 3
@@ -151,7 +152,7 @@ def test(cas_conn):
151152
continuity_con[i, year].set_rhs(demand[i])
152153
problem3.solve()
153154
print(so.get_solution_table(production, stock, extra_capacity,
154-
productive_capacity))
155+
productive_capacity))
155156
print(so.get_solution_table(manpower_con.get_expressions()))
156157

157-
return problem3.get_objective_value()
158+
return problem3.get_objective_value()

examples/factory_planning_1.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ def test(cas_conn):
7373
store[p, 6].set_bounds(lb=final_storage, ub=final_storage+1)
7474

7575
storageCost = storage_cost_per_unit * store.sum('*', '*')
76-
revenue = sum(product_data.at[p, 'profit'] * sell[p, t]
77-
for p in PRODUCTS for t in PERIODS)
76+
revenue = so.quick_sum(product_data.at[p, 'profit'] * sell[p, t]
77+
for p in PRODUCTS for t in PERIODS)
7878
m.set_objective(revenue-storageCost, sense=so.MAX, name='total_profit')
7979

8080
production_time = machine_type_product_data
8181
m.add_constraints((
82-
sum(production_time.at[mc, p] * make[p, t] for p in PRODUCTS) <=
83-
num_hours_per_period * num_machine_per_period.at[mc, t]
82+
so.quick_sum(production_time.at[mc, p] * make[p, t] for p in PRODUCTS)
83+
<= num_hours_per_period * num_machine_per_period.at[mc, t]
8484
for mc in MACHINE_TYPES for t in PERIODS), name='machine_hours')
8585
m.add_constraints(((store[p, t-1] if t-1 in PERIODS else 0) + make[p, t] ==
8686
sell[p, t] + store[p, t] for p in PRODUCTS

examples/factory_planning_2.py

+7-8
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

@@ -72,21 +71,21 @@ def test(cas_conn):
7271
store[p, 6].set_bounds(lb=final_storage, ub=final_storage+1)
7372

7473
storageCost = storage_cost_per_unit * store.sum('*', '*')
75-
revenue = sum(product_data.at[p, 'profit'] * sell[p, t]
76-
for p in PRODUCTS for t in PERIODS)
74+
revenue = so.quick_sum(product_data.at[p, 'profit'] * sell[p, t]
75+
for p in PRODUCTS for t in PERIODS)
7776
m.set_objective(revenue-storageCost, sense=so.MAX, name='total_profit')
7877

7978
num_machines_needing_maintenance = \
8079
machine_types_data['num_machines_needing_maintenance']
8180
numMachinesDown = m.add_variables(MACHINE_TYPES, PERIODS, vartype=so.INT,
8281
lb=0, name='numMachinesDown')
83-
m.add_constraints((sum(numMachinesDown[mc, t] for t in PERIODS) ==
84-
num_machines_needing_maintenance.at[mc]
85-
for mc in MACHINE_TYPES), name='maintenance')
82+
m.add_constraints((so.quick_sum(numMachinesDown[mc, t] for t in PERIODS) ==
83+
num_machines_needing_maintenance.at[mc]
84+
for mc in MACHINE_TYPES), name='maintenance')
8685
production_time = machine_type_product_data
8786
m.add_constraints((
88-
sum(production_time.at[mc, p] * make[p, t] for p in PRODUCTS) <=
89-
num_hours_per_period *
87+
so.quick_sum(production_time.at[mc, p] * make[p, t] for p in PRODUCTS)
88+
<= num_hours_per_period *
9089
(num_machine_per_period.at[mc, t] - numMachinesDown[mc, t])
9190
for mc in MACHINE_TYPES for t in PERIODS), name='machine_hours')
9291
m.add_constraints(((store[p, t-1] if t-1 in PERIODS else 0) + make[p, t] ==

0 commit comments

Comments
 (0)