+ All Categories
Home > Data & Analytics > Crude-Oil Blend Optimization in IMPL (IMPL-COBlending)

Crude-Oil Blend Optimization in IMPL (IMPL-COBlending)

Date post: 10-Aug-2015
Category:
Upload: alkis-vazacopoulos
View: 61 times
Download: 0 times
Share this document with a friend
Popular Tags:
29
Crude-Oil Blend Optimization in IMPL (IMPL-COBlending) “Multi-Component/Multi-Tank/Multi-Cut/Multi-Stream/Multi-Property Crude-Oil Blend Optimizer” i n d u s t r IAL g o r i t h m s LLC. (IAL) www.industrialgorithms.com July 2015 Introduction Presented in this short document is a description of how to use IMPL in a “mixed-language programming” environment (see IMPL-MixedLangProg) to model and solve a small crude-oil blending optimization problem in Excel/VBA. Crude-oil blending is a very important application in any oil-refinery which processes more than one crude-oil at a time since crude-oil disturbances or perturbations are known to be one of the largest types of disruptions that they will encounter. The multi- million dollar benefits of crude-oil blend scheduling can be found in Kelly and Mann (2003) where other details can be found in our other crude-oil blending related documents i.e., CCT-IMF and CTAP-IMF. The nonlinear production modeling details of crude-oil blending and fractionating can be found in Kelly (2004a), Menezes et. al. (2013), Kelly et. al. (2014) and Kelly and Zyngier (2015). Specifically, this crude-oil blending optimization problem is also known as a “mono time-period and non-convex pooling problem” which is very useful to locally optimize the next blend or mix of crude-oils to charge/feed the atmospheric and vacuum distillation units (CDU/VDU) or piepstills subject to nonlinear bounds and constraints such as volume- based compositions and mass-based/blending-indexed properties. This type of pooling problem is more complicated since we include more than just blending and storage with mixing and splitting equations but we are also required to include the crude-oil assay-data (i.e., distribution of yields and properties w.r.t. true or normal boiling- point temperatures) necessary to properly model the CDU/VDU fractionator unit-operations. To demonstrate the solution of this type of problem, we highlight a small but representative crude-oil blendshop quality optimization problem coded in Excel/VBA and IMPL where there is a mix of IML and IPL configuration data. It should be mentioned that this application can be downloaded upon request with a four (4) month trial license using open-source solvers.
Transcript

Crude-Oil Blend Optimization in IMPL (IMPL-COBlending)

“Multi-Component/Multi-Tank/Multi-Cut/Multi-Stream/Multi-Property Crude-Oil Blend Optimizer”

i n d u s t r IAL g o r i t h m s LLC. (IAL)www.industrialgorithms.com

July 2015

Introduction

Presented in this short document is a description of how to use IMPL in a “mixed-language programming” environment (see IMPL-MixedLangProg) to model and solve a small crude-oil blending optimization problem in Excel/VBA. Crude-oil blending is a very important application in any oil-refinery which processes more than one crude-oil at a time since crude-oil disturbances or perturbations are known to be one of the largest types of disruptions that they will encounter. The multi-million dollar benefits of crude-oil blend scheduling can be found in Kelly and Mann (2003) where other details can be found in our other crude-oil blending related documents i.e., CCT-IMF and CTAP-IMF. The nonlinear production modeling details of crude-oil blending and fractionating can be found in Kelly (2004a), Menezes et. al. (2013), Kelly et. al. (2014) and Kelly and Zyngier (2015).

Specifically, this crude-oil blending optimization problem is also known as a “mono time-period and non-convex pooling problem” which is very useful to locally optimize the next blend or mix of crude-oils to charge/feed the atmospheric and vacuum distillation units (CDU/VDU) or piepstills subject to nonlinear bounds and constraints such as volume-based compositions and mass-based/blending-indexed properties. This type of pooling problem is more complicated since we include more than just blending and storage with mixing and splitting equations but we are also required to include the crude-oil assay-data (i.e., distribution of yields and properties w.r.t. true or normal boiling-point temperatures) necessary to properly model the CDU/VDU fractionator unit-operations. To demonstrate the solution of this type of problem, we highlight a small but representative crude-oil blendshop quality optimization problem coded in Excel/VBA and IMPL where there is a mix of IML and IPL configuration data. It should be mentioned that this application can be downloaded upon request with a four (4) month trial license using open-source solvers.

Small Crude-Oil Blendshop Quality Optimization Synopsis

Here we focus only on the nonlinear quantity and quality details where the flowsheet is presented in Figure 1 and uses our Unit-Operation-Port-State Superstructure (UOPSS) as discussed in Kelly (2004b), Kelly (2005) and Zyngier and Kelly (2012). Other blending specific aspects can be found in Kelly and Mann (2003), Kelly (2006) and Kelly, Menezes and Grossmann (2014).

Figure 1. Small Crude-Oil Blendshop Flowsheet in UOPSS.

The static construction data of this UOPSS flowsheet can be found in the UPS file of Appendix A (note that the UPS file is generated by our GNOME Dia/Python drawing prototype). This problem has three (3) storage/receiving tanks (S1, S2, S3), one (1) crude-oil blender (COB) of sub-type blender, one (1) feed/charging tank (F1) and one (1) combined CDU/VDU pipestill of sub-type fractionator with four (4) streams N (naphtha), K (kerosene), D (diesel) and V (vacuum gasoils including vacuum residue). There are five (5) components or crude-oils taken from the on-line ExxonMobil crude-oil assay-data URL (see ASGBL14X.xlsx to CLAKBL13.xlsx). Appendix B contains the assay-data (ASY file) extracted from these Excel spreadsheets using six (6) cuts called LN, HN, K, D, VGO and VR. We have configured four (4) properties for this example as follows: N with RVP (Reid vapour pressure), K with FRZ (freeze-point), D with CLD (cloud-point) and V with SUL (sulfur). The RVP, FRZ and CLD each have property-transforms or blending-indices defined in the IML file located in Appendix C. The SUL property is a mass-based or heterogeneous property (i.e., volume-flow quantity times mass-property quality) and requires a corresponding density to also be configured which we have called SG for specific-gravity and this is assigned or associated only with the V compound or stream.

The IML file has the UPS file and the ASY file embedded as include-files and is called by the Excel/VBA application code found in Appendix D where its corresponding module code is found in Appendix E. IMPL inputs the static or master configuration data found in the IML file which constructs the UOPS structures, shapes or objects whereby all static and dynamic data can be unambiguously addressed, indexed, pointed to or referenced. Non-static data or dynamic data is configured directly in the Excel/VBA code using the various IPL functions and subroutines called in the Excel/VBA application code. Figure 2 shows the user interface programmed in 64-bit Excel/VBA Office 2013 where the “COBlending” sheet is interactive allowing the quantity and quality variable bounds to be changed interactively i.e., “~” is equals, “<” is less-than or equal and “>” is greater than or equal.

Figure 2. Small Crude-Oil Blendshop in Excel/VBA (Office 2013 64-Bit) and IMPL.

The purpose of this small crude-oil blend optimization is to blend from three (3) storage or receiving tanks with varying mixes of five (5) different crude-oil compositions into a one (1) feed or charging tank before it enters a CDU/VDU using nonlinear programming techniques such as SLP (IMPL’s SLPQPE) and SQP (IPOPT). Both stream (compound) yields and stream properties are bounded or constrained on the out-ports of the CDU/VDU in order to blend a mix of crude-oils which closely matches the quality bottlenecks and backoffs of the plant. It should be stressed, if an application such as this is run on a regular and persistent basis with just one time-period looking into the future, it is expected that significant benefits can be easily achieved (cf. Kelly and Mann, 2003 and IMPL-Benefits) with no capital investment i.e., just by running smarter!

Please contact Alkis Vazacopoulos ([email protected]) to obtain a free 4-month trial evaluation license of IMPL and the Excel workbook described using IPOPT and IMPL-SLPQPE with COINMP, GLPK and LPSOLVE as the nonlinear solvers.

References

Kelly, J.D., Mann, J.M., "Crude-oil blend scheduling optimization: an application with multi-million dollar benefits", Hydrocarbon Processing, June, 47, July, 72, (2003).

Kelly, J.D., "Formulating production planning models", Chemical Engineering Progress, January, 43, (2004a).

Kelly, J.D., "Production modeling for multimodal operations", Chemical Engineering Progress, February, 44, (2004b).

Kelly, J.D., "The unit-operation-stock superstructure (UOSS) and the quantity-logic-quality paradigm (QLQP) for production scheduling in the process industries", In: MISTA 2005 Conference Proceedings, 327, (2005).

Kelly, J.D., "Logistics: the missing link in blend scheduling optimization", Hydrocarbon Processing, June, 45, (2006).

Zyngier, D., Kelly, J.D., "UOPSS: a new paradigm for modeling production planning and scheduling systems", ESCAPE 22, June, (2012).

Menezes, B.C., Kelly, J.D., Grossmann, I.E., “Improved swing-cut modeling for planning and scheduling of oil-refinery distillation units”, Industrial and Engineering Chemistry Research, 52, (2013).

Kelly, J.D., Menezes, B.C., Grossmann, I.E., “Distillation blending and cutpoint temperature optimization using monotonic interpolation”, Industrial and Engineering Chemistry Research, 53, (2014).

IAL, “The benefits of IMPL (IMPL-Benefits)”, Slideshare, August, 2014.

IAL, “Crude-oil composition tracking/tracing industrial modeling framework (CCT-IMF)”, Slideshare, March, 2015.

IAL, “Crude-oil to tank assignment problem industrial modeling framework (CTAP-IMF)”, Slideshare, April, 2015.

Kelly, J.D., Zyngier, D., “Unit operation nonlinear modeling for planning and scheduling applications”, submitted to Optimization and Engineering, April, 2015.

http://www.exxonmobil.com/crudeoil/, accessed April, 2015.

IAL, “Mixed-language programming in IMPL (IMPL-MixedLangProg)”, Slideshare, June, 2015.

Appendix A – IMPL-COBlending.UPS File i M P l (c)

Copyright and Property of i n d u s t r I A L g o r i t h m s LLC.

checksum,82!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Unit-Operation-Port-State-Superstructure (UOPSS) *.UPS File.! (This file is automatically generated from the Python program IALConstructer.py)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

&sUnit,&sOperation,@sType,@sSubtype,@sUseCDU/VDU,,processc,fractionator,COB,,processc,blender%,D,,perimeter,,F1,,pool,,K,,perimeter,,N,,perimeter,,S1,,pool,,S2,,pool,,S3,,pool,,V,,perimeter,,&sUnit,&sOperation,@sType,@sSubtype,@sUse

! Number of UO shapes = 10

&sAlias,&sUnit,&sOperationALLPARTS,CDU/VDU,ALLPARTS,COB,ALLPARTS,D,ALLPARTS,F1,ALLPARTS,K,ALLPARTS,N,ALLPARTS,S1,ALLPARTS,S2,ALLPARTS,S3,ALLPARTS,V,&sAlias,&sUnit,&sOperation

&sUnit,&sOperation,&sPort,&sState,@sType,@sSubtypeCDU/VDU,,D,,out,CDU/VDU,,i,,in,CDU/VDU,,K,,out,CDU/VDU,,N,,out,CDU/VDU,,V,,out,COB,,i1,,in,COB,,i2,,in,COB,,i3,,in,COB,,o,,out,D,,i,,in,F1,,i,,in,F1,,o,,out,K,,i,,in,N,,i,,in,S1,,o,,out,S2,,o,,out,S3,,o,,out,V,,i,,in,&sUnit,&sOperation,&sPort,&sState,@sType,@sSubtype

! Number of UOPS shapes = 18

&sAlias,&sUnit,&sOperation,&sPort,&sStateALLINPORTS,CDU/VDU,,i,ALLINPORTS,COB,,i1,ALLINPORTS,COB,,i2,ALLINPORTS,COB,,i3,ALLINPORTS,D,,i,ALLINPORTS,F1,,i,ALLINPORTS,K,,i,ALLINPORTS,N,,i,ALLINPORTS,V,,i,ALLOUTPORTS,CDU/VDU,,D,ALLOUTPORTS,CDU/VDU,,K,ALLOUTPORTS,CDU/VDU,,N,ALLOUTPORTS,CDU/VDU,,V,ALLOUTPORTS,COB,,o,ALLOUTPORTS,F1,,o,ALLOUTPORTS,S1,,o,ALLOUTPORTS,S2,,o,ALLOUTPORTS,S3,,o,&sAlias,&sUnit,&sOperation,&sPort,&sState

&sUnit,&sOperation,&sPort,&sState,&sUnit,&sOperation,&sPort,&sStateCDU/VDU,,D,,D,,i,CDU/VDU,,K,,K,,i,CDU/VDU,,N,,N,,i,CDU/VDU,,V,,V,,i,COB,,o,,F1,,i,F1,,o,,CDU/VDU,,i,S1,,o,,COB,,i1,S2,,o,,COB,,i2,S3,,o,,COB,,i3,&sUnit,&sOperation,&sPort,&sState,&sUnit,&sOperation,&sPort,&sState

! Number of UOPSPSUO shapes = 9

&sAlias,&sUnit,&sOperation,&sPort,&sState,&sUnit,&sOperation,&sPort,&sStateALLPATHS,F1,,o,,CDU/VDU,,i,ALLPATHS,S1,,o,,COB,,i1,ALLPATHS,S2,,o,,COB,,i2,ALLPATHS,S3,,o,,COB,,i3,ALLPATHS,CDU/VDU,,D,,D,,i,ALLPATHS,COB,,o,,F1,,i,ALLPATHS,CDU/VDU,,K,,K,,i,ALLPATHS,CDU/VDU,,N,,N,,i,ALLPATHS,CDU/VDU,,V,,V,,i,&sAlias,&sUnit,&sOperation,&sPort,&sState,&sUnit,&sOperation,&sPort,&sState

Appendix B – IMPL-COBlending.ASY File i M P l (c) Copyright and Property of i n d u s t r I A L g o r i t h m s LLC.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

! Cut Data (Properties)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

&sCut,@rInitialPoint_Value,@rFinalPoint_ValueLN,60.0,165.0HN,165.0,330.0K,330.0,480.0D,480.0,650.0VGO,650.0,1000.0VR,1000.0,1499.0&sCut,@rInitialPoint_Value,@rFinalPoint_Value

&sComponent,&sCut,@rYield_ValueASGBL14X,LN,15.67/100.0,HN,32.88/100.0,K,17.60/100.0,D,14.34/100.0,VGO,12.98/100.0,VR,2.97/100.0AZRLT13F,LN,3.66/100.0,HN,13.36/100.0,K,16.3/100.0,D,20.84/100.0,VGO,31.68/100.0,VR,12.95/100.0BALDR14Z,LN,2.99/100.0,HN,10.05/100.0,K,12.83/100.0,D,20.12/100.0,VGO,33.93/100.0,VR,19.00/100.0BONGA14X,LN,3.81/100.0,HN,14.43/100.0,K,16.93/100.0,D,24.84/100.0,VGO,31.06/100.0,VR,7.96/100.0CLAKBL13,LN,11.78/100.0,HN,7.72/100.0,K,4.76/100.0,D,10.31/100.0,VGO,29.21/100.0,VR,35.39/100.0&sComponent,&sCut,@rYield_Value

&sComponent,&sCut,&sDensity,@rDensity_ValueASGBL14X,LN,SG,0.66,HN,SG,0.76,K,SG,0.81,D,SG,0.84,VGO,SG,0.88,VR,SG,0.96AZRLT13F,LN,SG,0.6593,HN,SG,0.754,K,SG,0.8071,D,SG,0.8428,VGO,SG,0.8966,VR,SG,0.9571BALDR14Z,LN,SG,0.67,HN,SG,0.76,K,SG,0.83,D,SG,0.87,VGO,SG,0.92,VR,SG,1.01BONGA14X,LN,SG,0.66,HN,SG,0.78,K,SG,0.84,D,SG,0.88,VGO,SG,0.94,VR,SG,0.98CLAKBL13,LN,SG,0.64,HN,SG,0.74,K,SG,0.85,D,SG,0.90,VGO,SG,0.96,VR,SG,1.07&sComponent,&sCut,&sDensity,@rDensity_Value

&sComponent,&sCut,&sComponent,@rComponent_Value&sComponent,&sCut,&sComponent,@rComponent_Value

&sComponent,&sCut,&sProperty,@rProperty_ValueASGBL14X,LN,RVP,12.56,HN,RVP,1.32,K,FRZ,-46.14,D,CLD,21.98,VGO,SUL,0.48,VR,SUL,1.18AZRLT13F,LN,RVP,0.0,HN,RVP,0.0,K,FRZ,-44.4,D,CLD,22.0,VGO,SUL,0.1919,VR,SUL,0.4232BALDR14Z,LN,RVP,13.29

,HN,RVP,1.15,K,FRZ,-56.29,D,CLD,5.40,VGO,SUL,0.65,VR,SUL,1.39BONGA14X,LN,RVP,12.68,HN,RVP,1.13,K,FRZ,-68.22,D,CLD,-6.99,VGO,SUL,0.34,VR,SUL,0.70CLAKBL13,LN,RVP,14.32,HN,RVP,1.68,K,FRZ,-105.19,D,CLD,-54.80,VGO,SUL,3.38,VR,SUL,6.17&sComponent,&sCut,&sProperty,@rProperty_Value

Appendix C – IMPL-COBlending.IML File i M P l (c) Copyright and Property of i n d u s t r I A L g o r i t h m s LLC.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Calculation Data (Parameters)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

&sCalc,@sValueSTART,-1.0BEGIN,0.0END,1.0PERIOD,1.0&sCalc,@sValue

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Chronological Data (Periods)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@rPastTHD,@rFutureTHD,@rTPDSTART,END,PERIOD@rPastTHD,@rFutureTHD,@rTPD

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Construction Data (Pointers)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Include-@sFile_NameIMPL-COBlending.upsInclude-@sFile_Name

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Capacity Data (Prototypes)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

&sUnit,&sOperation,@rRate_Lower,@rRate_UpperCOB,,0.0,100.0CDU/VDU,,0.0,50.0&sUnit,&sOperation,@rRate_Lower,@rRate_Upper

&sUnit,&sOperation,@rHoldup_Lower,@rHoldup_UpperS1,,0.0,150.0S2,,0.0,150.0S3,,0.0,150.0F1,,0.0,75.0&sUnit,&sOperation,@rHoldup_Lower,@rHoldup_Upper

&sUnit,&sOperation,&sPort,&sState,@rTeeRate_Lower,@rTeeRate_UpperALLINPORTS,0.0,1000.0ALLOUTPORTS,0.0,1000.0&sUnit,&sOperation,&sPort,&sState,@rTeeRate_Lower,@rTeeRate_Upper

&sUnit,&sOperation,&sPort,&sState,@rTotalRate_Lower,@rTotalRate_UpperALLINPORTS,0.0,1000.0ALLOUTPORTS,0.0,1000.0&sUnit,&sOperation,&sPort,&sState,@rTotalRate_Lower,@rTotalRate_Upper

&sUnit,&sOperation,&sPort,&sState,@rYield_Lower,@rYield_Upper,@rYield_FixedCOB,,i1,,0.0,1.0COB,,i2,,0.0,1.0COB,,i3,,0.0,1.0COB,,o,,1.0,1.0

CDU/VDU,,i,,1.0,1.0CDU/VDU,,N,,0.0,1.0CDU/VDU,,K,,0.0,1.0CDU/VDU,,D,,0.0,1.0CDU/VDU,,V,,0.0,1.0&sUnit,&sOperation,&sPort,&sState,@rYield_Lower,@rYield_Upper,@rYield_Fixed

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Constituent Data (Properties)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

&sDensitySG&sDensity

&sComponentASGBL14XAZRLT13FBALDR14ZBONGA14XCLAKBL13&sComponent

&sPropertyRVPFRZCLDSUL&sProperty

&sProperty,@sDensitySUL,SG&sProperty,@sDensity

Mask-&sPropertyMask-&sProperty

Properties-&sMacro,@sValueRVPindex,RVP^1.25RVPinverse,RVP^0.8

FRZindex,EXP(13.33*LN((FRZ+460.0)/600.0))FRZinverse,600.0*EXP(1.0/13.33*LN(FRZ))-460.0

CLDindex,EXP(12.5*LN((CLD+460.0)/600.0))CLDinverse,600.0*EXP(1.0/12.5*LN(CLD))-460.0Properties-&sMacro,@sValue

PropertyTransform-&sProperty,@sType,@rValue,@sValueRVP,$,1,RVPindexRVP,$,2,RVPinverse

FRZ,$,1,FRZindexFRZ,$,2,FRZinverse

CLD,$,1,CLDindexCLD,$,2,CLDinversePropertyTransform-&sProperty,@sType,@rValue,@sValue

&sUnit,&sOperation,&sPort,&sState,&sDensity,@rDensity_Lower,@rDensity_Upper,@rDensity_TargetCDU/VDU,,V,,SG,0.0,2.0,V,,i,,SG,0.0,2.0,&sUnit,&sOperation,&sPort,&sState,&sDensity,@rDensity_Lower,@rDensity_Upper,@rDensity_Target

&sUnit,&sOperation,&sPort,&sState,&sComponent,@rComponent_Lower,@rComponent_Upper,@rComponent_TargetS1,,o,,ASGBL14X,0.0,1.0,S1,,o,,AZRLT13F,0.0,1.0,S1,,o,,BALDR14Z,0.0,1.0,S1,,o,,BONGA14X,0.0,1.0,S1,,o,,CLAKBL13,0.0,1.0,S2,,o,,ASGBL14X,0.0,1.0,S2,,o,,AZRLT13F,0.0,1.0,S2,,o,,BALDR14Z,0.0,1.0,S2,,o,,BONGA14X,0.0,1.0,S2,,o,,CLAKBL13,0.0,1.0,S3,,o,,ASGBL14X,0.0,1.0,S3,,o,,AZRLT13F,0.0,1.0,S3,,o,,BALDR14Z,0.0,1.0,S3,,o,,BONGA14X,0.0,1.0,S3,,o,,CLAKBL13,0.0,1.0,

COB,,i1,,ASGBL14X,0.0,1.0,COB,,i1,,AZRLT13F,0.0,1.0,COB,,i1,,BALDR14Z,0.0,1.0,COB,,i1,,BONGA14X,0.0,1.0,COB,,i1,,CLAKBL13,0.0,1.0,COB,,i2,,ASGBL14X,0.0,1.0,COB,,i2,,AZRLT13F,0.0,1.0,COB,,i2,,BALDR14Z,0.0,1.0,COB,,i2,,BONGA14X,0.0,1.0,COB,,i2,,CLAKBL13,0.0,1.0,COB,,i3,,ASGBL14X,0.0,1.0,COB,,i3,,AZRLT13F,0.0,1.0,COB,,i3,,BALDR14Z,0.0,1.0,COB,,i3,,BONGA14X,0.0,1.0,COB,,i3,,CLAKBL13,0.0,1.0,COB,,o,,ASGBL14X,0.0,1.0,COB,,o,,AZRLT13F,0.0,1.0,COB,,o,,BALDR14Z,0.0,1.0,COB,,o,,BONGA14X,0.0,1.0,COB,,o,,CLAKBL13,0.0,1.0,

F1,,i,,ASGBL14X,0.0,1.0,F1,,i,,AZRLT13F,0.0,1.0,

F1,,i,,BALDR14Z,0.0,1.0,F1,,i,,BONGA14X,0.0,1.0,F1,,i,,CLAKBL13,0.0,1.0,F1,,o,,ASGBL14X,0.0,1.0,F1,,o,,AZRLT13F,0.0,1.0,F1,,o,,BALDR14Z,0.0,1.0,F1,,o,,BONGA14X,0.0,1.0,F1,,o,,CLAKBL13,0.0,1.0,

CDU/VDU,,i,,ASGBL14X,0.0,1.0,CDU/VDU,,i,,AZRLT13F,0.0,1.0,CDU/VDU,,i,,BALDR14Z,0.0,1.0,CDU/VDU,,i,,BONGA14X,0.0,1.0,CDU/VDU,,i,,CLAKBL13,0.0,1.0,&sUnit,&sOperation,&sPort,&sState,&sComponent,@rComponent_Lower,@rComponent_Upper,@rComponent_Target

&sUnit,&sOperation,&sPort,&sState,&sProperty,@rProperty_Lower,@rProperty_Upper,@rProperty_TargetCDU/VDU,,N,,RVP,0.0,100.0,N,,i,,RVP,0.0,100.0,CDU/VDU,,K,,FRZ,-200.0,100.0,K,,i,,FRZ,-200.0,100.0,CDU/VDU,,D,,CLD,-200.0,100.0,D,,i,,CLD,-200.0,100.0,CDU/VDU,,V,,SUL,0.0,10.0,V,,i,,SUL,0.0,10.0,&sUnit,&sOperation,&sPort,&sState,&sProperty,@rProperty_Lower,@rProperty_Upper,@rProperty_Target

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Cut Data (Properties)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Include-@sFile_NameIMPL-COBlending.asyInclude-@sFile_Name

&sUnit,&sOperation,&sPort,&sState,&sCut,@rYield_Lower,@rYield_UpperCDU/VDU,,N,,LN,1.0,1.0CDU/VDU,,N,,HN,1.0,1.0CDU/VDU,,K,,K,1.0,1.0CDU/VDU,,D,,D,1.0,1.0CDU/VDU,,V,,VGO,1.0,1.0CDU/VDU,,V,,VR,1.0,1.0&sUnit,&sOperation,&sPort,&sState,&sCut,@rYield_Lower,@rYield_Upper

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Cost Data (Pricing)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

&sUnit,&sOperation,@rFlowPro_Weight,@rFlowPer1_Weight,@rFlowPer2_Weight,@rFlowPen_Weight&sUnit,&sOperation,@rFlowPro_Weight,@rFlowPer1_Weight,@rFlowPer2_Weight,@rFlowPen_Weight

&sUnit,&sOperation,&sPort,&sState,@rFlowPro_Weight,@rFlowPer1_Weight,@rFlowPer2_Weight,@rFlowPen_WeightCDU/VDU,,i,,-60.0CDU/VDU,,N,,90.0CDU/VDU,,K,,75.0CDU/VDU,,D,,85.0CDU/VDU,,V,,55.0&sUnit,&sOperation,&sPort,&sState,@rFlowPro_Weight,@rFlowPer1_Weight,@rFlowPer2_Weight,@rFlowPen_Weight

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Content Data (Past, Present Provisos)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

&sUnit,&sOperation,@rHoldup_Value,@rStart_Time&sUnit,&sOperation,@rHoldup_Value,@rStart_Time

&sUnit,&sDensity,@rDensity_Value,@rStart_Time&sUnit,&sDensity,@rDensity_Value,@rStart_Time

&sUnit,&sComponent,@rComponent_Value,@rStart_Time&sUnit,&sComponent,@rComponent_Value,@rStart_Time

&sUnit,&sProperty,@rProperty_Value,@rStart_Time&sUnit,&sProperty,@rProperty_Value,@rStart_Time

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Command Data (Future Provisos)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

&sUnit,&sOperation,@rSetup_Lower,@rSetup_Upper,@rBegin_Time,@rEnd_TimeALLPARTS,1,1,BEGIN,END&sUnit,&sOperation,@rSetup_Lower,@rSetup_Upper,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,&sPort,&sState,&sUnit,&sOperation,&sPort,&sState,@rSetup_Lower,@rSetup_Upper,@rBegin_Time,@rEnd_TimeALLPATHS,1,1,BEGIN,END&sUnit,&sOperation,&sPort,&sState,&sUnit,&sOperation,&sPort,&sState,@rSetup_Lower,@rSetup_Upper,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,@rRate_Lower,@rRate_Upper,@rRate_Target,@rBegin_Time,@rEnd_Time&sUnit,&sOperation,@rRate_Lower,@rRate_Upper,@rRate_Target,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,@rHoldup_Lower,@rHoldup_Upper,@rHoldup_Target,@rBegin_Time,@rEnd_Time&sUnit,&sOperation,@rHoldup_Lower,@rHoldup_Upper,@rHoldup_Target,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,&sPort,&sState,@rTotalRate_Lower,@rTotalRate_Upper,@rTotalRate_Target,@rBegin_Time,@rEnd_Time&sUnit,&sOperation,&sPort,&sState,@rTotalRate_Lower,@rTotalRate_Upper,@rTotalRate_Target,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,&sPort,&sState,&sUnit,&sOperation,&sPort,&sState,@rRate_Lower,@rRate_Upper,@rRate_Target,@rBegin_Time,@rEnd_Time&sUnit,&sOperation,&sPort,&sState,&sUnit,&sOperation,&sPort,&sState,@rRate_Lower,@rRate_Upper,@rRate_Target,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,&sPort,&sState,@rYield_Lower,@rYield_Upper,@rYield_Target,@rBegin_Time,@rEnd_Time&sUnit,&sOperation,&sPort,&sState,@rYield_Lower,@rYield_Upper,@rYield_Target,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,&sPort,&sState,&sDensity,@rDensity_Lower,@rDensity_Upper,@rDensity_Target,@rBegin_Time,@rEnd_Time&sUnit,&sOperation,&sPort,&sState,&sDensity,@rDensity_Lower,@rDensity_Upper,@rDensity_Target,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,&sPort,&sState,&sComponent,@rComponent_Lower,@rComponent_Upper,@rComponent_Target,@rBegin_Time,@rEnd_Time&sUnit,&sOperation,&sPort,&sState,&sComponent,@rComponent_Lower,@rComponent_Upper,@rComponent_Target,@rBegin_Time,@rEnd_Time

&sUnit,&sOperation,&sPort,&sState,&sProperty,@rProperty_Lower,@rProperty_Upper,@rProperty_Target,@rBegin_Time,@rEnd_Time&sUnit,&sOperation,&sPort,&sState,&sProperty,@rProperty_Lower,@rProperty_Upper,@rProperty_Target,@rBegin_Time,@rEnd_Time

Appendix D – IMPL-Blending.XLS File (Excel/VBA IPL Application Code)'' i M P l (c)'' Copyright and Property of i n d u s t r I A L g o r i t h m s LLC.

Sub IMPL_COBlending() Dim path As String * IMPLlinestringlen Dim fact As String * IMPLlinestringlen Dim form As Long Dim fit As Long Dim filter As Long Dim focus As Long Dim face As Long Dim factor As Double Dim fob As Currency Dim frames As String * IMPLpagestringlen Dim filler As LongPtr Dim foreign As String * IMPLlinestringlen Dim force As Long Dim factorizer As Long Dim fork As Long Dim fresh As Long Dim flashback As Long Dim feedback As LongPtr Dim flag As Long Dim msg As String * IMPLlinestringlen Dim setting As Double Dim signal As Double Dim solver As String Dim name As String * IMPLbasestringlen Dim uname As String * IMPLbasestringlen Dim oname As String * IMPLbasestringlen Dim pname As String * IMPLbasestringlen Dim sname As String * IMPLbasestringlen Dim bname As String * IMPLbasestringlen Dim cname As String * IMPLbasestringlen Dim dthp, dthf, dtp As Double Dim lower, upper, target As Double Dim prowt, per1wt, per2wt, penwt As Double Dim starttime, begintime, endtime As Double Dim ptr_dll As LongLong Dim ptr_mdl As LongLong Dim rtn As Long Dim profit, performance1, performance2, penalty, total As Double Dim tpn, tfn As Long Dim value(1 To 1000) As Double

Dim i, j, k, m, n, t As Long Dim ncomps, nstanks, nftanks, nstrms As Long Dim compnames(1 To 10) As String * IMPLbasestringlen Dim stanknames(1 To 10), ftanknames(1 To 10) As String * IMPLbasestringlen Dim nstrmprops(1 To 10) As Long Dim strmnames(1 To 10) As String * IMPLbasestringlen Dim strmpropnames(1 To 10, 1 To 10) As String * IMPLbasestringlen ' Select the COBlending worksheet to start.

Worksheets("COBlending").Select ' Get the problem path where the IMPL DLL files are available.

Range("B1").Select path = Selection.value

' Change the directory to a location where the IMPL DLL's are available. ChDir Trim$(path) ' Get the problem name with its path included.

Range("B2").Select fact = Selection.value Range("I5").Select Selection.value = "" ' Set the "use log file" setting (USELOGFILE).

name = "USELOGFILE" rtn = IMPLreceiveSETTING(name, IMPLyes) ' Set the "non-naturally occurring number" setting (RNNON).

name = "RNNON" rtn = IMPLreceiveSETTING(name, IMPLrnnon) ' "Initialize" the problem environment.

rtn = IMPLroot(fact) If rtn = Int(IMPLrnnon) Then Selection.value = "%ERROR% - Invalid or missing license file." End ElseIf rtn > 0 Then Selection.value = "%ERROR% - Missing settings file." End ElseIf rtn < 0 Then Selection.value = "%WARNING% - Number of missing settings = " + Str$(-rtn) End End If

name = "USELOGFILE" setting = IMPLretrieveSETTING(name) msg = Trim(name) + " = " + Str$(Int(setting)) rtn = IMPLwritelog(msg) name = "RNNON" setting = IMPLretrieveSETTING(name) msg = Trim(name) + " = " + Str$(setting) rtn = IMPLwritelog(msg)

' Set the "remove floater" variables to "no".

name = "REMOVEFLOATERS" rtn = IMPLreceiveSETTING(name, IMPLno) setting = IMPLretrieveSETTING(name) msg = Trim(name) + " = " + Str$(Int(setting)) rtn = IMPLwritelog(msg)

' "Initialize" the problem memory.

rtn = IMPLreserve(fact, IMPLall) If rtn = Int(IMPLrnnon) Then Selection.value = "%ERROR% - Invalid or missing license file." End ElseIf rtn > 0 Then Selection.value = "%ERROR% - Missing memory file." End ElseIf rtn < 0 Then Selection.value = "%WARNING% - Missing missing setting." End End If

' "Interface" the problem data using the *.IML and *.UPS files.

form = IMPLsparsic fit = IMPLdiscrete filter = IMPLquality focus = IMPLoptimization face = IMPLimport factor = 1# fob = 0 frames = Chr$(0) rtn = IMPLinterfaceri(fact, form, fit, filter, focus, face, factor, fob, frames) If rtn = Int(IMPLrnnon) Then Selection.value = "%ERROR% - Invalid arguments." End ElseIf rtn > 0 Then Selection.value = "%ERROR% - Issue parsing import-file on line = " + Str$(rtn) End ElseIf rtn < 0 Then Selection.value = "%WARNING% - Issue parsing import-file on line = " + Str$(Abs(rtn)) End End If ' "Interact" with the problem data. ' Set the start-time, begin-time and end-time of the past/present and future time-horizons' respectively.

starttime = -1# begintime = 0# endtime = 1# ' Tank holdup openings. nstanks = 3 stanknames(1) = "S1" stanknames(2) = "S2" stanknames(3) = "S3" nftanks = 1 ftanknames(1) = "F1" Range("E16").Select oname = "" For i = 1 To nstanks uname = stanknames(i) name = Selection.value value(1) = Val(name) rtn = IMPLreceiveUOholdupopen(uname, oname, value(1), starttime, IMPLkeep) ActiveCell.Offset(1, 0).Select Next i For i = 1 To nftanks uname = ftanknames(i) name = Selection.value value(1) = Val(name) rtn = IMPLreceiveUOholdupopen(uname, oname, value(1), starttime, IMPLkeep) ActiveCell.Offset(1, 0).Select Next i ' Tank component (crude-oil) openings.'' These crude-oils are taken from the ExxonMobil on-line crude-oil Excel spreadsheets.

ncomps = 5 compnames(1) = "ASGBL14X" compnames(2) = "AZRLT13F" compnames(3) = "BALDR14Z" compnames(4) = "BONGA14X" compnames(5) = "CLAKBL13" Range("E22").Select For k = 1 To ncomps cname = compnames(k) For i = 1 To nstanks uname = stanknames(i) name = Selection.value value(1) = Val(name) rtn = IMPLreceiveUcomponentopen(uname, cname, value(1), starttime, IMPLkeep) ActiveCell.Offset(1, 0).Select Next i For i = 1 To nftanks uname = ftanknames(i) name = Selection.value value(1) = Val(name) rtn = IMPLreceiveUcomponentopen(uname, cname, value(1), starttime, IMPLkeep) ActiveCell.Offset(1, 0).Select Next i ActiveCell.Offset(-(nstanks + nftanks), 2).Select Next k ' CDU/VDU flow (rate) orders.

Range("C9").Select uname = "CDU/VDU" oname = "" lower = 0# upper = 50# target = IMPLrnnon name = Selection.value If InStr(name, ">") Then j = InStr(name, ">") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOrateorder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "<") Then j = InStr(name, "<") upper = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOrateorder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "~") Then j = InStr(name, "~") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) upper = lower rtn = IMPLreceiveUOrateorder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) End If ' COB recipe (inverse-yield) orders. Range("C11").Select uname = "COB" oname = "" sname = "" target = IMPLrnnon For i = 1 To nstanks pname = "i" + Trim$(Str$(i)) name = Selection.value

lower = 0# upper = 1# If InStr(name, ">") Then j = InStr(name, ">") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) / 100# rtn = IMPLreceiveUOPSyieldorder(uname, oname, pname, sname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "<") Then j = InStr(name, "<") upper = Val(Mid(name, j + 1, IMPLbasestringlen)) / 100# rtn = IMPLreceiveUOPSyieldorder(uname, oname, pname, sname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "~") Then j = InStr(name, "~") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) / 100# upper = lower rtn = IMPLreceiveUOPSyieldorder(uname, oname, pname, sname, lower, upper, target, begintime, endtime, IMPLkeep) End If ActiveCell.Offset(1, 0).Select Next i ' CDU/VDU out-port (stream) property orders. nstrms = 4 nstrmprops(1) = 1 nstrmprops(2) = 1 nstrmprops(3) = 1 nstrmprops(4) = 1 strmnames(1) = "N" strmnames(2) = "K" strmnames(3) = "D" strmnames(4) = "V" strmpropnames(1, 1) = "RVP" strmpropnames(2, 1) = "FRZ" strmpropnames(3, 1) = "CLD" strmpropnames(4, 1) = "SUL" Range("C16").Select uname = "CDU/VDU" oname = "" sname = "" target = IMPLrnnon For i = 1 To nstrms pname = strmnames(i) For k = 1 To nstrmprops(i) bname = strmpropnames(i, k) name = Selection.value lower = -200# upper = 1000# If InStr(name, ">") Then j = InStr(name, ">") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOPSpropertyorder(uname, oname, pname, sname, bname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "<") Then j = InStr(name, "<") upper = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOPSpropertyorder(uname, oname, pname, sname, bname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "~") Then j = InStr(name, "~") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) upper = lower rtn = IMPLreceiveUOPSpropertyorder(uname, oname, pname, sname, bname, lower, upper, target, begintime, endtime, IMPLkeep) End If Next k ActiveCell.Offset(1, 0).Select Next i ' CDU/VDU in-port component orders. Range("C21").Select uname = "CDU/VDU" oname = "" pname = "i" sname = "" target = IMPLrnnon For i = 1 To ncomps cname = compnames(i) name = Selection.value lower = 0# upper = 1# If InStr(name, ">") Then j = InStr(name, ">") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOPScomponentorder(uname, oname, pname, sname, cname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "<") Then j = InStr(name, "<") upper = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOPScomponentorder(uname, oname, pname, sname, cname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "~") Then j = InStr(name, "~") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) upper = lower rtn = IMPLreceiveUOPScomponentorder(uname, oname, pname, sname, cname, lower, upper, target, begintime, endtime, IMPLkeep) End If ActiveCell.Offset(1, 0).Select

Next i ' Tank holdup orders. Range("G16").Select oname = "" target = IMPLrnnon For i = 1 To nstanks uname = stanknames(i) name = Selection.value lower = 0# upper = 1000# If InStr(name, ">") Then j = InStr(name, ">") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOholduporder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "<") Then j = InStr(name, "<") upper = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOholduporder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "~") Then j = InStr(name, "~") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) upper = lower rtn = IMPLreceiveUOholduporder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) End If ActiveCell.Offset(1, 0).Select Next i For i = 1 To nftanks uname = ftanknames(i) name = Selection.value lower = 0# upper = 1000# If InStr(name, ">") Then j = InStr(name, ">") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOholduporder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "<") Then j = InStr(name, "<") upper = Val(Mid(name, j + 1, IMPLbasestringlen)) rtn = IMPLreceiveUOholduporder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) ElseIf InStr(name, "~") Then j = InStr(name, "~") lower = Val(Mid(name, j + 1, IMPLbasestringlen)) upper = lower rtn = IMPLreceiveUOholduporder(uname, oname, lower, upper, target, begintime, endtime, IMPLkeep) End If ActiveCell.Offset(1, 0).Select Next i ' Update or modify the past and future time-horizon durations and the time-period duration.

dthp = -1# dthf = 1# dtp = 1# rtn = IMPLreceiveT(dthp, dthf, dtp) ' "Serialize" the problem data.

rtn = IMPLrender(fact, IMPLall) ' "Model" the problem.

filler = IMPLsupplementalless foreign = IMPLsupplementaryless force = IMPLparameter rtn = IMPLmodelerv(fact, form, fit, filter, focus, filler, foreign, force) force = IMPLvariable rtn = IMPLmodelerv(fact, form, fit, filter, focus, filler, foreign, force) force = IMPLconstraint rtn = IMPLmodelerc(fact, form, fit, filter, focus, filler, foreign, force)

' "Output" the input-output data.

face = IMPLinout rtn = IMPLinterfacere(fact, form, fit, filter, focus, face, factor, fob, frames) face = IMPLoutin rtn = IMPLinterfacere(fact, form, fit, filter, focus, face, factor, fob, frames) face = IMPLinoutdata rtn = IMPLinterfacere(fact, form, fit, filter, focus, face, factor, fob, frames)

' "Presolve" and "solve" the problem.

factorizer = IMPLsemisolverless Range("G4").Select solver = Selection.value If Trim(solver) = "SLPQPE_COINMP" Then fork = IMPLslpqpecoinmp ElseIf Trim(solver) = "SLPQPE_GLPK" Then fork = IMPLslpqpeglpk ElseIf Trim(solver) = "SLPQPE_LPSOLVE" Then fork = IMPLslpqpelpsolve ElseIf Trim(solver) = "SLPQPE_CPLEX" Then

fork = IMPLslpqpecplex ElseIf Trim(solver) = "IPOPT" Then fork = IMPLipopt Else fork = IMPLslpqpecplex End If fresh = IMPLfirstsession flashback = IMPLbinaryfile feedback = IMPLsummonsless ' Get pointer or address to allow callback, pullback, feedback or summons from IMPL's Presolver.'' feedback = GetAddress(AddressOf summons)' Worksheets("Log").Select' Worksheets("Log").Range("A1").Select

rtn = IMPLpresolver(fact, form, fit, filter, focus, factorizer, fork, fresh, flashback, feedback) ' Display the solver status. Worksheets("COBlending").Select name = "STATUS" signal = IMPLretrieveSIGNAL(name) Worksheets("COBlending").Range("G8").Select If signal = IMPLconvergedall Then Selection.value = "CONVERGED" Else Selection.value = "UNCONVERGED" End If ' Display the completed timestamp.

Worksheets("COBlending").Range("H8").Select Selection.value = TimeValue(Now) ' Display the objective function term values.

Call IMPLretrieveOBJterms2(profit, performance1, performance2, penalty, total) Worksheets("COBlending").Range("B3").Select Selection.value = profit Worksheets("COBlending").Range("B4").Select Selection.value = performance1 Worksheets("COBlending").Range("B5").Select Selection.value = performance2 Worksheets("COBlending").Range("B6").Select Selection.value = penalty Worksheets("COBlending").Range("B7").Select Selection.value = total ' Get the number of time-periods in the "past/present" and "future" respectively.

Call IMPLretrieveT(tpn, tfn) ' Retrieve the QLQ phenomena using the UOPSS pointers (position/place/part).

' Display the CDU/VDU charge flow.

Worksheets("COBlending").Range("B9").Select uname = "CDU/VDU" oname = "" Call IMPLretrieveUOflow2(uname, oname, tpn, tfn, value(1)) Selection.value = value(1 + tpn) ' Display the crude-oil blender's recipes from the storage/receiving tanks.

Worksheets("COBlending").Range("B11").Select uname = "COB" oname = "" sname = "" For i = 1 To 3 pname = "i" + Trim$(Str$(i)) Call IMPLretrieveUOPSyield2(uname, oname, pname, sname, tpn, tfn, value(1)) Selection.value = value(1 + tpn) * 100# ActiveCell.Offset(1, 0).Select Next i ' Display the CDU/VDU out-port (stream) properties.

Worksheets("COBlending").Range("B16").Select uname = "CDU/VDU" oname = "" pname = "" sname = "" For i = 1 To nstrms pname = strmnames(i) For j = 1 To nstrmprops(i) bname = strmpropnames(i, j) Call IMPLretrieveUOPSproperty2(uname, oname, pname, sname, bname, tpn, tfn, value(1)) Selection.value = value(1 + tpn) ActiveCell.Offset(1, 0).Select Next j Next i

' Display the CDU/VDU in-port crude-oil compositions.

Worksheets("COBlending").Range("B21").Select uname = "CDU/VDU" oname = "" pname = "i" sname = "" For i = 1 To ncomps cname = compnames(i) Selection.value = Trim$(uname) + "," + Trim$(oname) + "," + Trim$(pname) + "," + Trim$(sname) Call IMPLretrieveUOPScomponent2(uname, oname, pname, sname, cname, tpn, tfn, value(1)) Selection.value = value(1 + tpn) ActiveCell.Offset(1, 0).Select Next i ' Display the tank holdups.

Worksheets("COBlending").Range("F16").Select For i = 1 To nstanks uname = stanknames(i) oname = "" Call IMPLretrieveUOholdup2(uname, oname, tpn, tfn, value(1)) For t = tpn + 1 To tpn + tfn Selection.value = value(t) ActiveCell.Offset(0, 1).Select Next t ActiveCell.Offset(1, -tfn).Select Next i For i = 1 To nftanks uname = ftanknames(i) oname = "" Call IMPLretrieveUOholdup2(uname, oname, tpn, tfn, value(1)) For t = tpn + 1 To tpn + tfn Selection.value = value(t) ActiveCell.Offset(0, 1).Select Next t ActiveCell.Offset(1, -tfn).Select Next i ' Display the tank crude-oil compositions.

Worksheets("COBlending").Range("F22").Select For i = 1 To nstanks uname = stanknames(i) For j = 1 To ncomps cname = compnames(j) Call IMPLretrieveUcomponent2(uname, cname, tpn, tfn, value(1)) For t = tpn + 1 To tpn + tfn Selection.value = value(t) ActiveCell.Offset(0, 2).Select Next t Next j ActiveCell.Offset(1, -ncomps * 2).Select Next i For i = 1 To nftanks uname = ftanknames(i) For j = 1 To ncomps cname = compnames(j) Call IMPLretrieveUcomponent2(uname, cname, tpn, tfn, value(1)) For t = tpn + 1 To tpn + tfn Selection.value = value(t) ActiveCell.Offset(0, 2).Select Next t Next j ActiveCell.Offset(1, -ncomps * 2).Select Next i ' Writeall of the problem data.

rtn = IMPLsummary(fact) rtn = IMPLwriteall(fact, IMPLseriesset, 0, 0) rtn = IMPLwriteall(fact, IMPLsimpleset, 0, 0) rtn = IMPLwriteall(fact, IMPLsymbolset, 0, 0) rtn = IMPLwriteall(fact, IMPLcatalog, 0, 0) rtn = IMPLwriteall(fact, IMPLlist, 0, 0) rtn = IMPLwriteall(fact, IMPLparameter, 0, 0) rtn = IMPLwriteall(fact, IMPLvariable, 0, 0) rtn = IMPLwriteall(fact, IMPLconstraint, 0, 0) rtn = IMPLwriteall(fact, IMPLformula, 0, 0) rtn = IMPLreport(fact) ' "De-initialize" the problem memory.

rtn = IMPLrelease(IMPLall) ' Write out the mnemonic *.ndt file which contains the symbolic notation of the model.

If form = IMPLsparsic And filter = IMPLquality Then rtn = IMPLroot(fact) rtn = IMPLreserve(fact, IMPLall) face = IMPLimport frames = Chr$(0) rtn = IMPLrestore(fact, IMPLall) form = IMPLsymbolic force = IMPLparameter

rtn = IMPLmodelerv(fact, form, fit, filter, focus, filler, foreign, force) force = IMPLvariable rtn = IMPLmodelerv(fact, form, fit, filter, focus, filler, foreign, force) force = IMPLconstraint rtn = IMPLmodelerc(fact, form, fit, filter, focus, filler, foreign, force) fork = IMPLsolverless fresh = IMPLfirstsession rtn = IMPLpresolver(fact, form, fit, filter, focus, factorizer, fork, fresh, flashback, feedback) ptr_dll = LoadLibrary("IMPLmodelerc") ptr_mdl = GetProcAddress(ptr_dll, "IMPLmodelerc") flag = 1 rtn = IMPLwritesensitivity(fact, ptr_mdl, flag) flag = 0 rtn = IMPLwritesymbology(fact, ptr_mdl, flag) rtn = IMPLrelease(IMPLall) End If Worksheets("COBlending").Select Worksheets("COBlending").Range("A1").Select End Sub

Appendix E – IMPL-Blending.XLS File (Excel/VBA IMPL Module Code)'' i M P l (c)'' Copyright and Property of i n d u s t r I A L g o r i t h m s LLC.

Option ExplicitOption Compare Text

' IMPL Resource Types. Global Const IMPLconstant = 0Global Const IMPLseriesset = 1Global Const IMPLsimpleset = 2Global Const IMPLsymbolset = 3Global Const IMPLcatalog = 4Global Const IMPLlist = 5Global Const IMPLparameter = 6Global Const IMPLvariable = 7Global Const IMPLconstraint = 8Global Const IMPLderivative = 9Global Const IMPLexpression = 10Global Const IMPLformula = 11Global Const IMPLworki = 12Global Const IMPLworkr = 13Global Const IMPLworkz = 14Global Const IMPLworks = 15Global Const IMPLall = 16 Global Const IMPLnumkeys = 8

' IMPL Resource Items. Global Const IMPLvalue = 0Global Const IMPLlower = 1Global Const IMPLupper = 2Global Const IMPLweight = 3Global Const IMPLtype = 4Global Const IMPLvalidation = 11Global Const IMPLvariance = 12Global Const IMPLvetistic = 13Global Const IMPLvaluation1 = 14Global Const IMPLvaluation2 = 15Global Const IMPLviolation = 16 ' IMPL Reference or Record Statuses. Global Const IMPLkeep = 1Global Const IMPLhide = 2Global Const IMPLerase = -1Global Const IMPLexpel = -2 ' IMPL String Sizes. Global Const IMPLbasestringlen = 64Global Const IMPLnamestringlenmult = 1Global Const IMPLkeystringlenmult = 8Global Const IMPLlinestringlenmult = 8Global Const IMPLpagestringlenmult = 64 Global Const IMPLnamestringlen = IMPLbasestringlen * IMPLnamestringlenmultGlobal Const IMPLkeystringlen = IMPLbasestringlen * IMPLkeystringlenmultGlobal Const IMPLlinestringlen = IMPLbasestringlen * IMPLlinestringlenmultGlobal Const IMPLpagestringlen = IMPLbasestringlen * IMPLpagestringlenmult ' IMPL Yes/No, On/Off, Open/Close, etc. Signs. Global Const IMPLyes = 1Global Const IMPLno = 0Global Const IMPLon = 1Global Const IMPLoff = 0

Global Const IMPLopen = 1Global Const IMPLclose = 0 ' IMPL Settings or Options (IMPL.set) Global Const IMPLuselogfile = -1Global Const IMPLrnnon = -99999#Global Const IMPLepsil = 0.0000000000001Global Const IMPLinfin = 1E+20Global Const IMPLcontol = 0.000001Global Const IMPLcomptol = 0#Global Const IMPLrandseed = 1Global Const IMPLperturbplus = 0.000000000001Global Const IMPLperturbtimes = 0.5Global Const IMPLabslogfuneps = 0.00001Global Const IMPLrellogfuneps = 0.00001Global Const IMPLmaxpasses = 50Global Const IMPLremovefloaters = 0Global Const IMPLpreemptpresolve = 0Global Const IMPLstatusoffset = 1000Global Const IMPLlowerrocl = 0#Global Const IMPLupperrocl = 1#Global Const IMPLlowerstcl = 2#Global Const IMPLupperstcl = 3#Global Const IMPLwritesolvernames = 0Global Const IMPLwritesolverlogfile = 0Global Const IMPLwritesolverlpfile = 0Global Const IMPLsymbology = 0Global Const IMPLsensitivity = 0Global Const IMPLstringnames = 0 ' IMPL Feed and Fact Flags. Global Const IMPLsourceless = ""Global Const IMPLsubjectless = "" ' IMPL Form Flag. Global Const IMPLstructureless = 0Global Const IMPLsparsic = 1Global Const IMPLsymbolic = 2 ' IMPL Fit Flag. Global Const IMPLslotless = 0Global Const IMPLdiscrete = 1Global Const IMPLdistribute = 2Global Const IMPLdifference = 3Global Const IMPLdifferential = 4 ' IMPL Filter Flag. Global Const IMPLselectless = 0Global Const IMPLquantity = 1Global Const IMPLlogistics = 2Global Const IMPLquality = 3Global Const IMPLqualogistics = 4 ' IMPL Focus Flag. Global Const IMPLsyllabusless = 0Global Const IMPLsimulation = 1Global Const IMPLestimation = 2Global Const IMPLoptimization = 3 ' IMPL Face Flag. Global Const IMPLstreamless = 0Global Const IMPLimport = 1Global Const IMPLexport = 2Global Const IMPLoutput = 3Global Const IMPLinput = 4Global Const IMPLinout = 6Global Const IMPLoutin = 5Global Const IMPLinoutdata = 7 ' IMPL Factor Flag. Global Const IMPLscale = 1# ' IMPL Fob Flag. Global Const IMPLsipherless = 0 ' IMPL Frames Flag.' (Chr$(0):VBA, c_char_p(b'\0'):Python/ctypes, string(char(0)):Julia). 'Global Const IMPLsheetsless = Chr$(0) ' IMPL Filler Flag. Global Const IMPLsupplementalless = 0 ' IMPL Foreign Flag.

Global Const IMPLsupplementaryless = "" ' IMPL Force Flag. Global Const IMPLstressless = 0 ' IMPL Factorizer Flag. Global Const IMPLsemisolverless = 0Global Const IMPLy12m = 1Global Const IMPLysmp = 2Global Const IMPLnspiv = 3Global Const IMPLma28 = 4Global Const IMPLpardiso = 5 ' IMPL Fork Flag. Global Const IMPLsolverless = 0Global Const IMPLcoinmp = 1Global Const IMPLglpk = 2Global Const IMPLlpsolve = 3Global Const IMPLscip = 4Global Const IMPLcplex = 5Global Const IMPLgurobi = 6Global Const IMPLlindo = 7Global Const IMPLoptonomy = 8Global Const IMPLxpress = 9Global Const IMPLconopt = 51Global Const IMPLipopt = 52Global Const IMPLknitro = 53Global Const IMPLnova = 54Global Const IMPLworhp = 55 Global Const IMPLslpqpecoinmp = 101Global Const IMPLslpqpeglpk = 102Global Const IMPLslpqpelpsolve = 103Global Const IMPLslpqpescip = 104Global Const IMPLslpqpecplex = 105Global Const IMPLslpqpegurobi = 106Global Const IMPLslpqpelindo = 107Global Const IMPLslpqpeoptonomy = 108Global Const IMPLslpqpexpress = 109Global Const IMPLslpqpeipopt = 152 Global Const IMPLsecqpey12m = 201Global Const IMPLsecqpeymsp = 202Global Const IMPLsecqpenspiv = 203Global Const IMPLsecqpema28 = 204Global Const IMPLsecqpepardiso = 205 Global Const IMPLsecqpesorve = 300Global Const IMPLsecqpey12msorve = 301Global Const IMPLsecqpeysmpsorve = 302Global Const IMPLsecqpenspivsorve = 303Global Const IMPLsecqpema28sorve = 304Global Const IMPLsecqpepardisosorve = 305 Global Const IMPLseosey12mmsorve = 401Global Const IMPLseoseysmpsorve = 402Global Const IMPLseosenspivsorve = 403Global Const IMPLseosema28sorve = 404Global Const IMPLseosepardisosorve = 405 Global Const IMPLspcrey12m = 501Global Const IMPLspcreysmp = 502Global Const IMPLspcrenspiv = 503Global Const IMPLspcrema28 = 504Global Const IMPLspcrepardiso = 505 Global Const IMPLsvve = 601Global Const IMPLssde = 602Global Const IMPLsfcme = 603 Global Const IMPLsbtecoinmp = 701Global Const IMPLsbteglpk = 702Global Const IMPLsbtelpsolve = 703 ' IMPL Fresh Flag. Global Const IMPLfirstsession = 0 ' IMPL Flashback Flag. Global Const IMPLbinaryfile = 0Global Const IMPLbinaryram = 1Global Const IMPLflatfile = 2 ' IMPL Feedback Flag. Global Const IMPLsummonsless = 0 ' IMPL Fuse Flag. Global Const IMPLcoldstart = 0Global Const IMPLwarmstart = 1

Global Const IMPLhotstart = 2 ' IMPL Fanfare Flag. Global Const IMPLshowseriesset = 0Global Const IMPLshowsimpleset = 1Global Const IMPLsymbolsetset = 2Global Const IMPLshowcatalog = 3Global Const IMPLshowlist = 4Global Const IMPLshowparameter = 5Global Const IMPLshowvariable = 6Global Const IMPLshowconstraint = 7Global Const IMPLshowformula = 8Global Const IMPLshowderivative = 9Global Const IMPLshowexpression = 10Global Const IMPLshowformulary = 11Global Const IMPLshowreport = 12Global Const IMPLshowsummary = 13Global Const IMPLshowstatics = 14Global Const IMPLshowslackness = 15Global Const IMPLshowscalings = 16Global Const IMPLshowall = 1073741823 ' IMPL Server Settings. ' USELOGFILE = If Yes (1) then use a log file else No (0) then no log file.' RNNON = Real Non-Naturally Occurring Number (-99,999).' INFIN = Near infinity (oo) value (1d+20).' EPSIL = Near zero (0) value (1d-13).' CONTOL = Constraint closure tolerance (1d-6).' COMPTOL = Compression tolerance (0d+0).' RANDSEED = Random number seed.' PERTURBPLUS = Plus perturbation size (1d-12).' PERTURBTIMES = Times perturbation size (0.5d+0).' ABSLOGFUNEPS = Absolute tolerance for logical functions such as IF, NOT, etc. (1d-5).' RELLOGFUNEPS = Relative tolerance for logical functions such as IF, NOT, etc. (1d-5).' MAXPASSES = Maximum number of presolver passes (50).' MAXPASSES = Maximum number of presolver passes (50).' REMOVEFLOATERS = If Yes (1) then remove floaters/following variables else No (0).' PREEMPTPRESOLVE = If Yes (1) then preempt, abort or stop presolve if infeasibility detected else No (0)' STATUSOFFSET = Solving - system 's status offset when status can be negative to make it positive (1000).' LOWERROCL = Lower rate-of-change value (0d+0).' UPPERROCL = Upper rate-of-change value (1d+0).' LOWERSTCL = Lower Student-t critical, threshold or control limit values (2d+0).' UPPERSTCL = Upper Student-t critical, threshold or control limit values (3d+0).' WRITESOLVERNAMES = If Yes (1) then write variable and constraint names in solver else No (0).' WRITESOLVERLOGFILE = If Yes (1) then write solver log file else No (0).' WRITESOLVERLPFILE = If Yes (1,2) then write solver lp,mps file else No (0).' WRITESYMBOLOGY = Write flag for symbology routine.' WRITESENSITIVITY = Write flag for sensitivity routine.' WRITESTRINGNAMES = Write number indices (0) versus name indices (1). ' IMPL Server Signals. ' SPRITE' SECURE' STREAM' SCALE' SELECT' SLOT' STRUCTURE' SYLLABUS' SUPPLEMENTAL' SIPHER' STAGE' SCENE' STEP' SUCCESSION' STALE' SESSION' SURPASS' SURPASS2' SEMISOLVER' SOLVER' STATUS' STATUS2' SOLUTION' SAVINGS' SUMMONS' SHOW' START' STRIDE ' IMPL Server Statistics. ' NVARTOTAL' NVAR' NVARNL' NCONTOTAL' NCON' NCONNL' NCONEQ' NDOF' NDERTOTAL' NDER

' NCONEXPTOTAL' NEXPTOTAL' OBJVALUE' ECLOSURE1' ECLOSURE2' ECLOSUREOO' ICLOSURE1' ICLOSURE2' ICLOSUREOO

' IMPL Server Solver Statuses.

Global Const IMPLbadderivatives = 1Global Const IMPLconvergedall = 2Global Const IMPLconvergedmost = 3Global Const IMPLconvergedonobj = 4Global Const IMPLconvergedwitherrors = 5Global Const IMPLdiverged = 6Global Const IMPLdegenerate = 7Global Const IMPLdualcutoff = 8Global Const IMPLfeasibleonly = 9Global Const IMPLincomplete = 10Global Const IMPLinfeasible = 11Global Const IMPLintegerinfeasible = 12Global Const IMPLinterrupted = 13Global Const IMPLlimitedprogress = 14Global Const IMPLmaxiterations = 15Global Const IMPLnodof = 16Global Const IMPLnofeasible = 17Global Const IMPLnumericalfailure = 18Global Const IMPLoptimal = 19Global Const IMPLpresolvedonly = 20Global Const IMPLprimalcutoff = 21Global Const IMPLsearchaborted = 22Global Const IMPLsearchfailed = 23Global Const IMPLsuboptimal = 24Global Const IMPLsystemaborted = 25Global Const IMPLtimedout = 26Global Const IMPLunbounded = 27Global Const IMPLunconverged = 28Global Const IMPLundefined = 29Global Const IMPLunexpectedfailure = 30Global Const IMPLunfinished = 31Global Const IMPLunloaded = 32Global Const IMPLuseraborted = 33 ' IMPL Server Routines. Declare PtrSafe Function IMPLroot Lib "IMPLserver.dll" (ByVal IMLPsprb As String) As LongDeclare PtrSafe Function IMPLreserve Lib "IMPLserver.dll" (ByVal IMPLsprb As String, ByVal IMPLtype As Long) As Long

Declare PtrSafe Function IMPLreceiveSETTING Lib "IMPLserver.dll" (ByVal IMPLsetting As String, ByVal IMPLvalue As Double) As LongDeclare PtrSafe Function IMPLretrieveSETTING Lib "IMPLserver.dll" (ByVal IMPLsetting As String) As DoubleDeclare PtrSafe Function IMPLretrieveSIGNAL Lib "IMPLserver.dll" (ByVal IMPLsignal As String) As DoubleDeclare PtrSafe Function IMPLretrieveSTATISTIC Lib "IMPLserver.dll" (ByVal IMPLstatistic As String) As Double

Declare PtrSafe Function IMPLrender Lib "IMPLserver.dll" (ByVal IMPLsprb As String, ByVal IMPLtype As Long) As LongDeclare PtrSafe Function IMPLrestore Lib "IMPLserver.dll" (ByVal IMPLsprb As String, ByVal IMPLtype As Long) As Long

Declare PtrSafe Function IMPLrefresh Lib "IMPLserver.dll" (ByVal IMPLtype As Long) As LongDeclare PtrSafe Function IMPLresize Lib "IMPLserver.dll" (ByVal IMPLtype As Long, ByVal IMPLnum As Long, ByVal IMPLrank As Long, ByVal IMPLrange As Long, ByVal IMPLlen As Long, ByVal IMPLlenprime As Long, ByVal IMPLlenprime2 As Long, ByVal IMPLlenkey As Long, ByVal IMPLlenval As Long) As LongDeclare PtrSafe Function IMPLrelease Lib "IMPLserver.dll" (ByVal IMPLtype As Long) As Long

Declare PtrSafe Function IMPLwritelog Lib "IMPLserver.dll" (ByVal IMPLmessage As String) As LongDeclare PtrSafe Function IMPLwriteall Lib "IMPLserver.dll" (ByVal IMPLsprb As String, ByVal IMPLtype As Long, ByVal IMPLtypebegin As Long, ByVal IMPLtypeend As Long) As LongDeclare PtrSafe Function IMPLreport Lib "IMPLserver.dll" (ByVal IMPLsprb As String) As Long

Declare PtrSafe Function IMPLrow Lib "IMPLserver.dll" (ByVal IMPLname As String, ByRef IMPLkeys As Long) As LongDeclare PtrSafe Function IMPLreview1 Lib "IMPLserver.dll" (ByVal IMPLtype As Long, ByVal IMPLrow As Long, ByVal IMPLitem As Long) As DoubleDeclare PtrSafe Sub IMPLreview2 Lib "IMPLserver.dll" (ByVal IMPLtype As Long, ByVal IMPLnrow As Long, ByVal IMPLrow As Long, ByVal IMPLitem As Long, ByRef IMPLvalue As Double)Declare PtrSafe Function IMPLrevise1 Lib "IMPLserver.dll" (ByVal IMPLtype As Long, ByVal IMPLrow As Long, ByVal IMPLitem As Long) As DoubleDeclare PtrSafe Sub IMPLrevise2 Lib "IMPLserver.dll" (ByVal IMPLtype As Long, ByVal IMPLnrow As Long, ByVal IMPLrow As Long, ByVal IMPLitem As Long, ByRef IMPLvalue As Double)

Declare PtrSafe Function IMPLsummary Lib "IMPLserver.dll" (ByVal IMPLsprb As String) As Long

Public Declare PtrSafe Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPtrPublic Declare PtrSafe Function GetProcAddress Lib "kernel32" (ByVal hModule As LongPtr, ByVal lpProcName As String) As LongPtrDeclare PtrSafe Function IMPLwritesensitivity Lib "IMPLserver.dll" (ByVal IMPLsprb As String, ByRef IMPLptrmdl As LongPtr, ByVal IMPLflag As Long) As LongDeclare PtrSafe Function IMPLwritesymbology Lib "IMPLserver.dll" (ByVal IMPLsprb As String, ByRef IMPLptrmdl As LongPtr, ByVal IMPLflag As Long) As Long

' IMPL Interfacer, Modeler and Presolver Routines.

Declare PtrSafe Function IMPLinterfaceri Lib "IMPLinterfaceri.dll" (ByVal IMPLfact As String, ByVal IMPLform As Long, ByVal IMPLfit As Long, ByVal IMPLfilter As Long, ByVal IMPLfocus As Long, ByVal IMPLface As Long, ByVal IMPLfactor As Double, ByVal IMPLfob As Currency, ByVal IMPLframes As String) As Long

Declare PtrSafe Function IMPLinterfacere Lib "IMPLinterfacere.dll" (ByVal IMPLfact As String, ByVal IMPLform As Long, ByVal IMPLfit As Long, ByVal IMPLfilter As Long, ByVal IMPLfocus As Long, ByVal IMPLface As Long, ByVal IMPLfactor As Double, ByVal IMPLfob As Currency, ByVal IMPLframes As String) As LongDeclare PtrSafe Function IMPLmodelerv Lib "IMPLmodelerv.dll" (ByVal IMPLfact As String, ByVal IMPLform As Long, ByVal IMPLfit As Long, ByVal IMPLfilter As Long, ByVal IMPLfocus As Long, ByRef IMPLfiller As LongPtr, ByVal IMPLforeign As String, ByRef IMPLforce As Long) As LongDeclare PtrSafe Function IMPLmodelerc Lib "IMPLmodelerc.dll" (ByVal IMPLfact As String, ByVal IMPLform As Long, ByVal IMPLfit As Long, ByVal IMPLfilter As Long, ByVal IMPLfocus As Long, ByRef IMPLfiller As LongLong, ByVal IMPLforeign As String, ByRef IMPLforce As Long) As LongDeclare PtrSafe Function IMPLpresolver Lib "IMPLpresolver.dll" (ByVal IMPLfact As String, ByVal IMPLform As Long, ByVal IMPLfit As Long, ByVal IMPLfilter As Long, ByVal IMPLfocus As Long, ByVal IMPLfactorizer As Long, ByVal IMPLfork As Long, ByVal IMPLfresh As Long, ByVal IMPLflashback As Long, ByRef IMPLfeedback As LongPtr) As Long

' IMPL Interacter Routines.

Declare PtrSafe Function IMPLreceiveT Lib "IMPLinteracter.dll" (ByVal IMPLdthp As Double, ByVal IMPLdthf As Double, ByVal IMPLdtp As Double) As Long

Declare PtrSafe Function IMPLreceiveUOflowweight Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLprowt As Double, ByVal IMPLper1wt As Double, ByVal IMPLperwt2 As Double, ByVal IMPLpenwt As Double, ByVal IMPLstatus As Long) As LongDeclare PtrSafe Function IMPLreceiveUOPSflowweight Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLprowt As Double, ByVal IMPLper1wt As Double, ByVal IMPLperwt2 As Double, ByVal IMPLpenwt As Double, ByVal IMPLstatus As Long) As Long

Declare PtrSafe Function IMPLreceiveUOholdupopen Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLvalue As Double, ByVal IMPLstart As Double, ByVal IMPLstatus As Long) As LongDeclare PtrSafe Function IMPLreceiveUOholduporder Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLlower As Double, ByVal IMPLupper As Double, ByVal IMPLtarget As Double, ByVal IMPLbegin As Double, ByVal IMPLend As Double, ByVal IMPLstatus As Long) As LongDeclare PtrSafe Function IMPLreceiveUOrateorder Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLlower As Double, ByVal IMPLupper As Double, ByVal IMPLtarget As Double, ByVal IMPLbegin As Double, ByVal IMPLend As Double, ByVal IMPLstatus As Long) As LongDeclare PtrSafe Function IMPLreceiveUOPSrateorder Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLlower As Double, ByVal IMPLupper As Double, ByVal IMPLtarget As Double, ByVal IMPLbegin As Double, ByVal IMPLend As Double, ByVal IMPLstatus As Long) As LongDeclare PtrSafe Function IMPLreceiveUOPSyieldorder Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLlower As Double, ByVal IMPLupper As Double, ByVal IMPLtarget As Double, ByVal IMPLbegin As Double, ByVal IMPLend As Double, ByVal IMPLstatus As Long) As Long

Declare PtrSafe Function IMPLreceiveProperty Lib "IMPLinteracter.dll" (ByVal IMPLbname As String, ByVal IMPLstatus As Long) As LongDeclare PtrSafe Function IMPLreceiveUOPSproperty Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLbname As String, ByVal IMPLlower As Double, ByVal IMPLupper As Double, ByVal IMPLtarget As Double, ByVal IMPLstatus As Long) As Long

Declare PtrSafe Function IMPLreceiveUcomponentopen Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLcname As String, ByVal IMPLvalue As Double, ByVal IMPLstart As Double, ByVal IMPLstatus As Long) As LongDeclare PtrSafe Function IMPLreceiveUOPScomponentorder Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLcname As String, ByVal IMPLlower As Double, ByVal IMPLupper As Double, ByVal IMPLtarget As Double, ByVal IMPLbegin As Double, ByVal IMPLend As Double, ByVal IMPLstatus As Long) As LongDeclare PtrSafe Function IMPLreceiveUOPSpropertyorder Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLbname As String, ByVal IMPLlower As Double, ByVal IMPLupper As Double, ByVal IMPLtarget As Double, ByVal IMPLbegin As Double, ByVal IMPLend As Double, ByVal IMPLstatus As Long) As Long

Declare PtrSafe Sub IMPLretrieveT Lib "IMPLinteracter.dll" (ByRef IMPLtpn As Long, ByRef IMPLtfn As Long)Declare PtrSafe Sub IMPLretrieveOBJterms2 Lib "IMPLinteracter.dll" (ByRef IMPLprofit As Double, ByRef IMPLperformance1 As Double, ByRef IMPLperformance2 As Double, ByRef IMPLpenalty As Double, ByRef IMPLtotal As Double)

Declare PtrSafe Sub IMPLretrieveUOflow2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal tpn As Long, ByVal tfn As Long, ByRef value As Double)Declare PtrSafe Sub IMPLretrieveUOholdup2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal tpn As Long, ByVal tfn As Long, ByRef value As Double)Declare PtrSafe Sub IMPLretrieveUOPSflow2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal tpn As Long, ByVal tfn As Long, ByRef value As Double)Declare PtrSafe Sub IMPLretrieveUOPSyield2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal tpn As Long, ByVal tfn As Long, ByRef value As Double)

Declare PtrSafe Sub IMPLretrieveUcomponent2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLcname As String, ByVal tpn As Long, ByVal tfn As Long, ByRef value As Double)Declare PtrSafe Sub IMPLretrieveUOPSdensity2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLdname As String, ByVal tpn As Long, ByVal tfn As Long, ByRef value As Double)Declare PtrSafe Sub IMPLretrieveUOPScomponent2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLcname As String, ByVal tpn As Long, ByVal tfn As Long, ByRef value As Double)Declare PtrSafe Sub IMPLretrieveUOPSproperty2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLbname As String, ByVal tpn As Long, ByVal tfn As Long, ByRef value As Double)

Declare PtrSafe Function IMPLUOm Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String) As LongDeclare PtrSafe Function IMPLUOPSij Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String) As LongDeclare PtrSafe Function IMPLDd Lib "IMPLinteracter.dll" (ByVal IMPLdname As String) As LongDeclare PtrSafe Function IMPLCc Lib "IMPLinteracter.dll" (ByVal IMPLcname As String) As LongDeclare PtrSafe Function IMPLBb Lib "IMPLinteracter.dll" (ByVal IMPLbname As String) As LongDeclare PtrSafe Function IMPLAa Lib "IMPLinteracter.dll" (ByVal IMPLaname As String) As LongDeclare PtrSafe Function IMPLLl Lib "IMPLinteracter.dll" (ByVal IMPLlname As String) As Long

' IMPL Presolver Callback to Excel/VBA routines.

Declare PtrSafe Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As LongPtr) As Long

Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpvDest As String, ByVal lpvSource As LongPtr, ByVal NumBytes As Long)

Function Ptr2Str(ptr As LongPtr) As String Dim l As Long If ptr = 0 Then Ptr2Str = vbNullString Else l = lstrlen(ptr) Ptr2Str = Space$(l) CopyMemory Ptr2Str, ptr, l End IfEnd Function

Function GetAddress(ByVal ptrAddressOf As LongPtr) As LongPtr GetAddress = ptrAddressOfEnd Function

Function summons(ByRef msglen As Long, ByRef msgptr As LongPtr) As Long Dim msg As String msg = Ptr2Str(msgptr) Worksheets("Log").Select Selection.value = Trim$(msg) ActiveCell.Offset(1, 0).Select ' IMPL User code here ...

End Function


Recommended