Interface between SIMO optimizer and JLP linear programming library.
Parameters:
Initialize optimizer:
>>> epsilon = 0.00001
>>> from simo.optimization.jlp import JLP
>>> execfile('optimization/test/mocks4optimizer.py')
>>> chart_path = 'optimization/test'
>>> jlp = JLP(logger, logname, taskdef, simdbin, simdbout, False, False,
... chart_path, True, 'test', True)
Called Logger.log_message(
'optimization-test',
'ERROR',
"Parameter 'maxobjects' missing")
Called Logger.log_message(
'optimization-test',
'ERROR',
"Parameter 'jfolder' missing")
Called Logger.log_message(
'optimization-test',
'ERROR',
"Parameter 'prefix' missing")
>>> jlp = JLP(logger, logname, taskdef, simdbin, simdbout, False, False,
... chart_path, True, 'test', True,
... maxobjects=1000, jfolder='', prefix='test')
Construct J input files, run J program as a subprocess and process J output
Process unit split by the JLP algorithm
Process JLP output when the problem is infeasible
Parameters:
respath – result file path, str iteration – iteration indice, int
Copy JLP result file to result folder
Parameters:
iteration – iteration indice, int
Read and process solution from JLP output files
Remove J input and output files
Parameters:
stack – postfix stack, list
Update infix stack:
>>> stack = [['a'], ['b']]
>>> jlp._update_stack(stack)
>>> print stack
[['a', 'b']]
Parameters:
num_of_expr – number of expressions as integer expressions – SIMO postfix expressions in a list
Process invalid constraint postfix expression:
>>> jlp._init_ok = True
>>> jlp._process_const_expr(2, invalid_taskdef.constraints)
Called Logger.log_message(
'optimization-test',
'ERROR',
"Invalid operator for J '/'")
Called Logger.log_message(
'optimization-test',
'ERROR',
'JLP condition right hand side must be a numerical value')
>>> jlp.j_consts.infix # doctest: +NORMALIZE_WHITESPACE
['c0_V11_endv0 / c0_V1_endv1 > 1.05',
'c1_Volume21_endv0 > c1_Volume11_endv1']
>>> jlp.j_consts.names
['c0_V11_endv0', 'c0_V1_endv1', 'c1_Volume21_endv0']
>>> jlp.j_consts.order
[0, 1, 0]
>>> print jlp._init_ok
False
Process constraint postfix expression back to infix form and try to figure out if the expression is good for JLP:
>>> jlp._process_const_expr(3, taskdef.constraints)
>>> jlp.j_consts.infix # doctest: +NORMALIZE_WHITESPACE
[u'c0_V20_20v0 - c0_V10_10v1 > 0.00',
u'c1_Volume20_endv0 - c1_Volume10_endv1 > 0.00',
'variable1 - variable2 > 0.00']
>>> jlp.j_consts.names # doctest: +NORMALIZE_WHITESPACE
[u'c0_V20_20v0', u'c0_V10_10v1', u'c1_Volume20_endv0',
u'c1_Volume10_endv1', u'c2_V20_20v0', u'c2_AREA20_20v1',
u'c2_V10_10v2', u'c2_AREA10_10v3']
>>> jlp.j_consts.order
[0, 1, 0, 1, 0, 1, 2, 3]
Parameters:
partype – parameter type, either ‘init’ or ‘close’
Write J parameter file (j.par):
>>> jlp._write_j_par('init')
>>> fp = open('j.par', 'r')
>>> contents = fp.read()
>>> print contents
!1000
;incl('test_problem.txt')
<BLANKLINE>
>>> fp.close()
Write the optimisation problem definition to a file for J:
>>> jlp._obj_vars = ['x0', 'x1']
>>> jlp._write_j_problem()
>>> fp = open('test_problem.txt', 'r')
>>> contents = fp.read()
>>> print contents # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
* READ OBJECTIVE AND CONSTRAINT VARIABLE VALUES FROM FILE *
udat=data(read->(id,nbranch),in->'test_unitdata.txt')
sdat=data(read->(x0,x1,c0_V20_20v0,c0_V10_10v1,c1_Volume20_endv0,c1_Volume10_endv1,c2_V20_20v0,c2_AREA20_20v1,c2_V10_10v2,c2_AREA10_10v3), in->'test_vardata.txt')
linkdata(data->udat,subdata->sdat,nobsw->nbranch)
<BLANKLINE>
* TRANSFORM ILLEGAL CONSTRAINTS *
strans=trans()
variable1 = c2_V20_20v0 * c2_AREA20_20v1
variable2 = c2_V10_10v2 * c2_AREA10_10v3
/
<BLANKLINE>
* OPTIMISATION PROBLEM DEFINITION *
pr=problem()
<BLANKLINE>
* OBJECTIVE FUNCTION DEFINITION *
0.3*x0+0.7*x1==max
<BLANKLINE>
* CONSTRAINT DEFINITIONS *
c0_V20_20v0 - c0_V10_10v1 > 0.00
c1_Volume20_endv0 - c1_Volume10_endv1 > 0.00
variable1 - variable2 > 0.00
/
jlp(problem->pr,data->udat,subtrans->strans,report->'...jlp_output.txt')
branch_report=trans()
do(i,1,weights())
write('test_bresult.txt',$,matrix%udat(unit(i),1),schedw(i),price%unit(unit(i)))
enddo
/
weight_report=trans()
do(i,1,partweights())
write('test_wresult.txt',$,partunit(i),partschedw(i),partweight(i))
enddo
/
;if(Feasible);then
call(branch_report)
call(weight_report)
;else
write('test_bresult.txt','(~infeasible problem~)')
;endif
end
>>> fp.close()
Write the optimisation data to two data files for J. The unit data contains the simulation unit id and number of simulated alternatives for each unit. The variable contains the objective and constraint variable values for each alternative in each simulation unit:
>>> omatrix2.task_def = taskdef
>>> jlp._data = omatrix2
>>> jlp._write_j_data() # doctest: +ELLIPSIS
Called OMatrix._evaluator.evaluate(...)
>>> fp = open('test_unitdata.txt', 'r')
>>> print fp.read()
0,2
1,5
2,3
3,4
4,1
<BLANKLINE>
>>> fp.close()
>>> fp = open('test_vardata.txt', 'r')
>>> print fp.read()
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
1.2345,1.2345,4.69,4.69,4.69,4.69,4.69,4.69,4.69,4.69
<BLANKLINE>
>>> fp.close()