Accessing Attachments
As described in the Developer Guide, Xpress Insight allows files to be attached to an app or scenario. While the model is running within Xpress Insight, the Mosel interface will allow you to query, read and edit attachments of the scenario being run, as well as query and read (but not edit) attachments of the app to which that scenario belongs.
To demonstrate the use of an app and scenario attachments, in this example we have a Distances array that we want to populate with distances between cities. As this will not change, it would be very wasteful to store a copy of these in every scenario of the app, so we store them in a file distances.dat which is attached to the app. In the example, we call insightgetappattach to copy this file to the working directory and then populate the Distances array from this. (It is assumed that the app has a companion-file that configures the Distances array as unmanaged by Xpress Insight.)
To demonstrate the use of scenario attachments, we then save the model's results to a file decorated with today's date, and attach this file to the current scenario.
model RoutePlanner uses "mmxprs" ! Load the Xpress-Optimizer uses "mminsight" ! Load the Insight interface public declarations EvaluationDate: string Cities: set of string Distances: array(Cities,Cities) of real TrafficLevels: array(Cities,Cities) of real routetaken: array(Cities,Cities) of mpvar end-declarations ! Procedure to build and solve optimization problem procedure runproblem ! Download app attachment if insightgetmode <> INSIGHT_MODE_NONE then ! Model is running within Insight, so download distances.dat from Insight server insightgetappattach("distances.dat") if insightattachstatus<>INSIGHT_ATTACH_OK then writeln("Failed to download app attachment") exit(1) end-if else ! Model is running outside of Insight, attachments are not accessible ! so copy from some other location fcopy( '/Users/me/myfiles/distances.dat', 'distances.dat' ) end-if ! Load into model initializations from "distances.dat" Distances end-initializations ! Perform optimization buildproblem optimizeproblem ! Capture results to file ROUTES_FNAME := "result-"+EvaluationDate+".dat" fopen(ROUTES_FNAME,F_OUTPUT) forall (s in Cities, d in Cities | routetaken(s,d).sol=1) writeln(s,"->",d) fclose(F_OUTPUT) ! Store as scenario attachment if insightgetmode <> INSIGHT_MODE_NONE then ! Model is running within Insight, so upload distances.dat to Insight server insightputscenattach(ROUTES_FNAME) if insightattachstatus<>INSIGHT_ATTACH_OK then writeln("Failed to upload scenario attachment") exit(1) end-if end-if end-procedure case insightgetmode of INSIGHT_MODE_LOAD: do loaddata end-do INSIGHT_MODE_RUN: do insightpopulate runproblem end-do INSIGHT_MODE_NONE: do loaddata runproblem end-do else writeln("Unknown execution mode") end-case end-model
For clarity, the implementation of the loaddata, buildproblem and optimizeproblem procedures have been omitted from the example.
© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.