Mixed-Language Programming in IMPL (IMPL-MixedLangProg) i n d u s t r IAL g o r i t h m s LLC. (IAL) www.industrialgorithms.com June 2015 Introduction Presented in this short document is a description of how to use IMPL in a “mixed-language programming” (MLP) concept i.e., using IML (Industrial Modeling Language) and IPL (Industrial Programming Language). We also demonstrate how IMPL can be called from Excel/VBA which is another example of MLP. The notion of mixed-language programming is to employ the best programming language for each specific part of the overall problem solution. Though IML and IPL can configure identical problems with both logistics and quality phenomenological characteristics, it is useful, for example, to configure static or time-invariant data in IML and dynamic or time- variant data in IPL. The system architecture of IMPL which enables MLP is a “global address space” (GAS) memory for all of its sets, lists, parameters, formulas, variables, constraints and derivatives. This is the same enabling technology used for conventional MLP when binding C/C++ to Java/Julia for instance. This ultimately means that an insert, update, view and delete occurs globally within the IMPL data-bank so any interfacing and/or interaction that occurs after that point has maximal consistency and integrity as well as minimal redundancy since there is only one data repository or store. It should also be mentioned however that this is global or common memory within an IMPL instance or image only. If multiple IMPL images are spawned simultaneously or concurrently on different processors or threads, the IMPL memory address space is local to each image. More specifically, how IMPL implements this system architecture is through IMPL’s SSIIMPLE (Server, Solvers, Interfacer, Interacter, Modeler, Presolver Libraries and Executable) system architecture where the Server shown in Figure 1 is at the center. Both the Interfacer (IML) and Interacter (IPL) bind, connect or link to the Server which stores and manages the IMPL data. Once the problem data has been created and contained, then the Modeler, Presolver and Solvers can access the data quickly and efficiently.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Mixed-Language Programming in IMPL (IMPL-MixedLangProg)
i n d u s t r IAL g o r i t h m s LLC. (IAL)www.industrialgorithms.com
June 2015
Introduction
Presented in this short document is a description of how to use IMPL in a “mixed-language programming” (MLP) concept i.e., using IML (Industrial Modeling Language) and IPL (Industrial Programming Language). We also demonstrate how IMPL can be called from Excel/VBA which is another example of MLP. The notion of mixed-language programming is to employ the best programming language for each specific part of the overall problem solution. Though IML and IPL can configure identical problems with both logistics and quality phenomenological characteristics, it is useful, for example, to configure static or time-invariant data in IML and dynamic or time-variant data in IPL.
The system architecture of IMPL which enables MLP is a “global address space” (GAS) memory for all of its sets, lists, parameters, formulas, variables, constraints and derivatives. This is the same enabling technology used for conventional MLP when binding C/C++ to Java/Julia for instance. This ultimately means that an insert, update, view and delete occurs globally within the IMPL data-bank so any interfacing and/or interaction that occurs after that point has maximal consistency and integrity as well as minimal redundancy since there is only one data repository or store. It should also be mentioned however that this is global or common memory within an IMPL instance or image only. If multiple IMPL images are spawned simultaneously or concurrently on different processors or threads, the IMPL memory address space is local to each image.
More specifically, how IMPL implements this system architecture is through IMPL’s SSIIMPLE (Server, Solvers, Interfacer, Interacter, Modeler, Presolver Libraries and Executable) system architecture where the Server shown in Figure 1 is at the center. Both the Interfacer (IML) and Interacter (IPL) bind, connect or link to the Server which stores and manages the IMPL data. Once the problem data has been created and contained, then the Modeler, Presolver and Solvers can access the data quickly and efficiently.
Figure 1. IMPL’s SSIIMPLE System Architecture.
IMPLServer
IMPLPresolver
IMPLModeler
IMPLSolversIMPLInterface
r
IMPLInteracter
To demonstrate these concepts, we highlight a small but representative gasoline blendshop quality optimization problem coded in Excel/VBA and IMPL where there is a mix of IML and IPL configured data.
Small Gasoline 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 (2004), 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 2. Small Gasoline 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 five (5) components each with two (2) tanks and two (2) products or grades also with two (2) tanks each. There is a single blend header with two (2) operations of Regular and Premium. There is one (1) density and twelve (12) properties (RON, MON, ROAD, RVP, ARO, BEN, E70, E100, E150, E225, SUL and VLI). The SUL property is a mass-based property, RVP is a blending-index (property-transform) where ROAD and VLI are derived-properties (properties-property). All of the static capacity and capability data are found in the IML file of Appendix B.
The IML file has the UPS file embedded as an include-file and is called by the Excel/VBA application code found in Appendix C where its corresponding module code is found in Appendix D. All of the IMPL and IPL 64-bit procedure declarations are found in the Excel/VBA module code using 64-bit pointer addresses (VBA LongPtr and C LongLong integer types) when passing procedure, function or subroutine pointers. The IMPL Interfacer inputs the static configuration data found in the IML file which constructs the UOPS structures, shapes or objects whereby all static and dynamic data can be properly and uniquely addressed, indexed, pointed to or referenced.
Figure 2 shows the user interface programmed in 64-bit Excel/VBA Office 2013 where the “Blendshop” sheet is interactive allowing the quantity and quality variable bounds to be changed i.e., “~” is equals, “<” is less-than or equal and “>” is greater than or equal. The “Rundown” and “Inventory” sheets contain the optimized component flows and tank holdups respectively where the “Log” sheet displays the callback or feedback log from IMPL’s Presolver back to VBA (cf. function “summons” in Appendix D). Note that “callbacks” are well-known in MLP because they provide the necessary interaction between one system and the other especially when one of the systems takes longer to run than the other and notifications of its progress is prudent.
Figure 3. Small Gasoline Blendshop in Excel/VBA (Office 2013 64-Bit) and IMPL.
To manage the dynamic and user data, IPL is employed to interactively modify and/or over-load the static data as required using several IPL routines listed below which can be seen in Appendix C using the concept of orders, transactions, commands or provisos:
These IPL “receive” functions allow the application code to insert and/or update any of the problem static and dynamic data before the IMPL Modeler is called to configure the dependent sets, lists and parameters as well as to create the variables, constraints and derivatives before the IMPL Presolver is called to presolve and solve the problem. For this implementation, we can call IPOPT or IMPL’s SLPQPE nonlinear solver which uses CPLEX, COINMP, GLPK and LPSOLVE as the LP sub-solver.
Once the problem has been solved i.e., converged all variables and constraints to an acceptable level of tolerance, IPL subroutines and functions can be called to “retrieve” or view the solution-data as follows:
When the known or valid UOPS names are used to call these routines then multiple time-periods can be retrieved from IMPL to Excel/VBA using a one-dimensional (1D) array (Value(1)) pointing to its first array index. The integers “tpn” and “tfn” are required by IMPL to specify the number of time-periods in the past/present and the number of time-periods in the future. For those computer programming languages where it is difficult to access vector or 1D array data, IPL has corresponding retrieve functions which passes back one value only for the specified time-period index.
In summary, we have shown how to configure a small gasoline blending optimization problem using some mix of IMPL’s IML (usually static or model-data) and IPL (usually dynamic or cycle-data) as well as being interfaced and interacted with Excel/VBA which is also an example of MLP.
Please contact Alkis Vazacopoulos ([email protected]) to obtain a trial evaluation license of IMPL and the Excel workbook described.
References
Kelly, J.D., "Production modeling for multimodal operations", Chemical Engineering Progress, February, 44, (2004).
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).
Zyngier, D., Kelly, J.D., "UOPSS: a new paradigm for modeling production planning and scheduling systems", ESCAPE 22, June, (2012).
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., "Logistics: the missing link in blend scheduling optimization", Hydrocarbon Processing, June, 45, (2006).
Kelly, J.D., Menezes, B.C., Grossmann, I.E., “Distillation blending and cutpoint temperature optimization using monotonic interpolation”, Industrial and Engineering Chemistry Research, 53, 15146-15156, (2014).
Appendix A – IMPL-Blendshop-QQ.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,242!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Unit-Operation-Port-State-Superstructure (UOPSS) *.UPS File.! (This file is automatically generated from the Python program IALConstructer.py)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Appendix B – IMPL-Blendshop-QQ.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,@sValue
START,0.0BEGIN,0.0END,1.0PERIOD,1.0
! Basis: flow UoM = KB, time UoM = day
! Conversion from m3 to US barrel.M32B,1.0/0.1589873
! Conversion from US barrel to thousand US barrel (KB).B2KB,1.0/1000.0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Chronological Data (Periods)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Construction Data (Pointers)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Capacity Data (Prototypes)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Constituent Data (Properties)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Cost Data (Pricing)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Command Data (Future Provisos)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Appendix C – IMPL-Blendshop-QQ.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.
Option Explicit
Sub IMPL_Blendshop_QQ() 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 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 nprops, nrundowns, ntanks As Long Dim propnames(1 To 100) As String * IMPLbasestringlen Dim rundownnames(1 To 100) As String * IMPLbasestringlen Dim tanknames(1 To 100) As String * IMPLbasestringlen Dim matnames(1 To 100) As String * IMPLbasestringlen ' Select the Blendshop worksheet to start.
Worksheets("Blendshop").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
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. ' PRICE weights.
rtn = IMPLpresolver(fact, form, fit, filter, focus, factorizer, fork, fresh, flashback, feedback) ' Display the solver status. Worksheets("Blendshop").Select name = "STATUS" signal = IMPLretrieveSIGNAL(name) Worksheets("Blendshop").Range("G8").Select If signal = IMPLconvergedall Then Selection.value = "CONVERGED" Else Selection.value = "UNCONVERGED" End If ' Display the completed timestamp.
Worksheets("Blendshop").Range("H8").Select Selection.value = TimeValue(Now) ' Display the objective function term values.
Call IMPLretrieveOBJterms2(profit, performance1, performance2, penalty, total) Worksheets("Blendshop").Range("B3").Select Selection.value = profit Worksheets("Blendshop").Range("B4").Select Selection.value = performance1 Worksheets("Blendshop").Range("B5").Select Selection.value = performance2 Worksheets("Blendshop").Range("B6").Select Selection.value = penalty Worksheets("Blendshop").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).
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 = 0 rtn = IMPLwritesymbology(fact, ptr_mdl, flag) rtn = IMPLrelease(IMPLall) End If Worksheets("Blendshop").Select Worksheets("Blendshop").Range("A1").Select End Sub
Appendix D – IMPL-Blendshop-QQ.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.
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 LongDeclare 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 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 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 LongDeclare PtrSafe Function IMPLreceiveUpropertyopen Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLbname As String, ByVal IMPLvalue As Double, ByVal IMPLstart 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 IMPLretrieveUOPSproperty2 Lib "IMPLinteracter.dll" (ByVal IMPLuname As String, ByVal IMPLoname As String, ByVal IMPLpname As String, ByVal IMPLsname As String, ByVal IMPLuname 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 LongDeclare 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 ...