Knowledge Base Article
Rapid Python Model Deployment with FICO® Xpress Insight
A Facility Location Problem Example — Xpress 8.9 & Insight 4.53
Table of Contents
- FICO® Xpress Optimization
- FICO Xpress Insight
- Overview, Benefits and Capabilities
- FICO Xpress Workbench
- Overview and Benefits
- Insight Python Apps – Development Workflow
- FICO Xpress Insight
- Preparing Your Python Model
- General Steps to Modify Your Python Model
- Modify Your Python Model – An Example
- Creating Custom Views with View Designer
- Add a New View Under a New View Group Named Control Panel
- Add Demand Table with a Table Name
- Configure Demand Table as Multi-Scenario
- Add a Form: Total Cost
- Add a Simple Chart (Multi-Scenario)
- Add Execution Button to Load Default Data
- Add Run Model Execution Button
- Xpress Installation and Python Setup
- Install FICO Xpress
- Install FICO Xpress Insight
- Link Python Installation to FICO Xpress Optimization
Note: The purpose of this content is to provide an example for Python users new to FICO® Xpress Optimization for building simple Insight Python applications. Other examples such as the Getting Started (Quick Start) guide and another basic Insight app can be found in the Insight Developers Guide for Python here.
Useful Links:
- FICO Xpress Optimization Online Help
- FICO Xpress Insight Python Package Reference
- FICO Xpress Insight 4 Developers Guide For Python
- FICO Xpress Optimization Group
- FICO Xpress Community License
- FICO Xpress Optimization Examples Repository
- FICO Xpress Insight Short Video Tutorial Series
- FICO Xpress Mosel Short Video Tutorial Series
1. FICO Xpress Optimization
FICO® Xpress Insight
Overview
FICO Xpress Insight is a comprehensive platform for building analytical solutions including AI, optimization, and machine learning. It provides easy ways to create, deploy and utilize solutions based on scalable high-performance algorithms. Insight is a flexible modeling and development environment for both on-premises and cloud installations. FICO Xpress Insight is designed to reduce time to deployment by providing out of the box features and components that Operational Researchers and Data Scientists need to build interactive applications to operationalize their models, without any HTML/JavaScript or web development knowledge.
Key Benefits:
- FICO Xpress Insight helps organizations to rapidly construct analytical and optimization solutions that address specific use cases.
- Xpress Insight is IT-independent and not hindered by data limitations.
- FICO software is geared to reduce the burden on IT and address their critical requirements while empowering business users to take ownership of decisions and change management.
- It is easy to use by data science and operations research professionals, as well as business analysts and business users.
- FICO Xpress Insight provides:
- An easy-to-use web client experience
- Interactive visualizations
- Ability to embed custom views (tables, forms, charts) created using View Designer
- Ability to embed Tableau and JavaScript views in Insight application views
- Scenario analysis tools (for simulation purposes) including the ability to run what-if analysis and compare scenarios side-by-side
- Ability to edit scenario parameters and inputs to re-run Python models for what-if analysis and compare scenarios within the user interface
- Built-in scenario management
- Ability to clone, rename, and delete scenarios
- Attach files to apps or scenarios
- A secure multi-user environment and built-in user management features
- The underlying model of an Xpress Insight app (Python or Mosel) can call any optimization solver: FICO Xpress Solver, 3rd party commercial solvers or open-source solvers.
- FICO Xpress Insight can connect to 3rd party data sources and other web services as needed.
- FICO Xpress Insight contains a data repository to store data based for every application and scenario.
FICO® Xpress Workbench
Overview and Benefits:
Xpress Workbench is an application for creating and editing and debugging Xpress Insight applications. Xpress Workbench enables Python Insight solution developers (Operations Research and Data Science professionals) to:
- Create Xpress Insight Python projects and edit source files
- Build custom interactive views (with ables, forms, charts, buttons) via drag and drop using View Designer
- Publish Xpress Insight Python applications to Insight Server (one click publishing)
- Debug Xpress Insight scenarios to inspect the model data at the end of the run (no debugging of Python code itself)
The app creation overall workflow is depicted in Figure 3.
Figure 3. Xpress Insight Application Development – Rapid App Development
Insight Python Apps – Development Workflow
STEP 1
Open FICO Xpress Workbench application from Start Menu. In Workbench HOME page, click CREATE PROJECT > CREATE INSIGHT (PYTHON) PROJECT. Select a location for the Project and create a folder named My Python Example and click Select Folder. This will load your new Project into Xpress Workbench.
STEP 2
Click on My Python Example folder and expand the sub-folders. Xpress Workbench creates sub-directories that form a basic Insight Python Project, which includes:
- python_source folder (3) – where your Python code/logic sits
- model_resrouces folder (2) – which holds your model resource files (input files, if any)
- client_resources folder (1) – this folder hosts Insight application interactive view details (*.vdl files)
- XML companion file (4) – this file outlines the list of:
- View Groups along with the order of your Insight app views
- App attachment tag names for your app attachments, if any
- Table details used by Tableau views, if any
STEP 3
Place your data files (if any) in model_resources folder.
STEP 4
Place your Python model in python_source folder. Save your Python file as application.py to overwrite the existing file and follow steps described in "Preparing Your Python Model" to make it compatible with FICO Xpress Insight.
STEP 5
Create custom views by following steps described in "Creating Custom Views with View Designer".
STEP 6
Publish your Python Insight app to FICO Xpress Insight.
STEP 7
From your web browser login to your FICO Xpress Insight account (http://localhost:8860) to view your Insight view groups and views. The default username and password are admin and admin123, respectively.
STEP 8
Open your Insight Python application and click on the scenario shelf (grey bar). Click New Scenario and change your scenario name to My Base Scenario and click Save. This will create and load your scenario default data.
STEP 9
Select your scenario to place it on the scenario shelf (grey bar) as an active scenario. Hit Run from your scenario drop-down and browse to your views to view your input and result views.
STEP 10
Clone your base scenario and rename it My Second Scenario. Modify an input parameter and re-run your second scenario and place it on the scenario shelf (grey bar) to compare results side-by-side.
An optimization and/or analytical model defines a set of input entities to receive scenario data and a set of result entities that will be populated with the optimization/analytical solution. The solution is the set of values representing the decisions identified by the optimization process or values suggested by analytical models along with other data synthesized from these values. In FICO Xpress Insight applications, a scenario contains the input data and results from the model. Business users will be able to modify/adjust/tweak input parameters to these analytical models to run what-if analysis and to run, clone, and compare what-if analysis across multiple scenarios.
Figure 6. Scenario LifecycleTo summarize, FICO Xpress Insight powers an agile joint development and deployment process, linking business users closely with the Data Science team. The two figures below depict how business users can quickly evaluate, understand, and build trust in solutions that match the way they think about their jobs.
A comparison of business users' workflow versus solution developers' workflow is provided in Figures 7 & 8.
Figure 7:Xpress Insight Applications – Business Users WorkflowFigure 8:Xpress Insight Applications – Developers Workflow
2. Preparing Your Python Model
General Steps to Modify Your Python Model
Note that your Python file should be renamed to application.py and placed into the python_source folder.
STEP 1
Import FICO Xpress Insight library.
import xpressinsight as xi
STEP 2
Create a unique class (one for each app) representing the Python Xpress Insight application. This class inherits from base class ‘xpressinsight.AppBase’ and can have any name. This class contains the definition of data models and different execution modes.
class MyApp(xi.AppBase) : # Data model and execution modes
Meta-data of the app is supplied by decorating this class using ‘xpressinsight.AppConfig’. It contains parameters to specify:
- Application name
- Application version (using Semantic Versioning)
- Configurations for result data handling within the Insight server (deletion of result data when a scenario input-data is edited /scenario is queued for execution is the default configuration).
@xi.AppConfig(name="App Name", version=xi.AppVersion(1, 0, 0)) class MyApp(xi.AppBase): # Data model and execution modesPyCharm Intellisense
STEP 3
Declare model paramater and entitites.
- Define single valued entities parameters using ‘xpressinsight.Scalar’: We can specify the datatype of a scalar, give it a default value, and set an alias for the scalar which corresponds to its name as an UI entity. This scalar can correspond to an input value or a result value, and its content can be updated after execution.
MyInt : xi.Scalar(dtype=xi.integer, alias='My Integer', manage=xi.Manage.INPUT)
- Single valued constants can be similarly defined using ‘xpressinsight.Param’.
- Declare your data models by using ‘xpressinsight.DataFrame’ or ‘xpressinsight.Series’.
- ‘xpressinsight.Index’ to create single-level/multi-level indices for DataFrame/Series.
- ‘xpressinsight.Series’ is preferred when there is only column/attribute in the data.
- ‘xpressinsight.DataFrame’ is preferred when there are multiple columns/attributes in the data (slower execution than Series).
STEP 4
Create a function to load data to Xpress Insight entities. Use ‘xpressinsight.ExecModeLoad’ to decorate this function (which takes a description as an argument).
@xi.ExecModeLoad(descr="Loads input data.") def exec_mode_load(self): # Load Data
STEP 5
Create a function pertaining to execution of optimization/analytics on the loaded Insight entities. Use ‘xpressinsight.ExecModeRun’ to decorate this function (which takes a description as argument).
@xi.ExecModeRun(descr="Takes input data and uses it to compute the results.") def exec_mode_run(self): # Code
Modify Your Python Model - An Example
We will now implement the steps described above on a capacitated facility location optimization example that you can find online here. You can also download the Xpress Insight app example here. As per the online example, we used an open source solver to solve this problem. However, you can use other solvers, including commercial (and community) versions of FICO Xpress.
The capacitated facility location problem consists of picking the best amongst a set of potential facility sites (indexed by j ranging from 1 to m) with a known capacity (Mj), to satisfy customer demand (di). The objective is to pick a subset of facility sites in a way to minimize total set up cost to open facilities (fj) plus total transportation cost (cij) to fulfill the demand. With the above assumptions, we introduce our first set of binary decision variables yj to be 1 if and only if facility j is open and our second set of continuous shipment quantity variables xij to be the amount shipped from facility j to customer i.
- The objective function of the capacitated facility location problem can be formulated as the following, which is the minimization of the sum of fixed costs for opening facilities plus transportation costs for all active lanes:
- The constraints of capacitated facility location problem can be formulated as:
This set of constraints make sure that sum of shipment quantities from all facilities to customer i is equal to its demand, guaranteeing that demand is satisfied.
These constraints gaurantee that for every facility j that is open, sum of shipment quantities originating that facility to all customers should be less than or equal to its capacity.
These constraints indicate that shipment quantity from facility j to customer i is less than or equal to demand at customer i. Note that this is a redundant set of constraints only added to tighten LP relaxation of the problem.
Non-negativity constraints. This set of constraints make sure that optimized values of shipment quantity decision variables cannot be negative.
These constraints indicate that decision variable yj can only take binary values, 0 if facility is closed and 1 if facility is open.
The capacitated facility location problem has the following inputs:
- Demand at customer locations
- Transportation cost from facilities to customer locations
- Fixed cost for each facility and its associated capacity
The output of the optimization model can be summarized as:
- Which facilities are chosen
- Total set up cost to open facilities plus transportation costs
- Shipment amount from each facility to customer locations
We will now demonstrate how you can simply convert this Python formulation into an application that can enables business users to take advantage of the facility location model from the example. Here are the steps to set up your application.py:
STEP 1
Import the packages (if needed install them, e.g., via ‘pip install PuLP’):
import pandas as pd import xpressinsight as xi from pulp import * # Import PuLP library import numpy as np
STEP 2
Define the name: we use the decorator class @xi.AppConfig to define the name of the application and its version. You can optionally set the result_data argument to delete on execute to prevent scenario result data from evaporating when input data is changed in the UI.
@xi.AppConfig(name="Facility Location Problem", version=xi.AppVersion(1, 0, 0),result_data=xi.ResultData(delete=xi.ResultDataDelete.ON_EXECUTE))
STEP 3
Declare data models in InsightApp class. This includes any parameters and inputs (entities exposed to user), and results (output entities after optimization run is complete):
- All parameters are declared using variables names followed by “:” and xi.Param and defining the data type for the parameter. In our case, we are declaring Tolerance (TOL) and names of the input files.
class InsightApp(xi.AppBase): # Declaring file names as parameter. TOL:xi.Param(0.5) CapacityFile:xi.Param("capacity.csv", dtype=xi.string) FacilityCostFile:xi.Param("faccost.csv", dtype=xi.string) TranspCostFile:xi.Param("transportcost.csv", dtype=xi.string) DemandFile: xi.Param("customers.csv", dtype=xi.string)
- We then declare our model inputs such as set of customers, customer demand, set of facilities, set up cost and capacity for each facility, and unit transportation cost. We declare Customer and Facility sets using xi.index while the rest are declared as xi.Series or xi.DataFrame. We need to specify datatypes. By default, all declared entities are managed as INPUT. The display name of entities within the UI can be specified using the alias argument.
# Declaring Data Models Customer:xi.Index(dtype=xi.integer,manage=xi.Manage.INPUT) # this is set of customers for optimization # Declare customer demand series indexed on customer Demand: xi.Series(index=['Customer'],dtype=xi.integer,manage=xi.Manage.INPUT) # demand for each customer Facility: xi.Index(dtype=xi.string,manage=xi.Manage.INPUT) # this is the set of facility for optimization FixedCost: xi.Series(index=['Facility'],dtype=xi.real,manage=xi.Manage.INPUT) # cost to open up a facility Capacity: xi.Series(index=['Facility'],dtype=xi.integer,manage=xi.Manage.INPUT) # capacity for each facility # transportation cost from facilities to customers TransportCost: xi.Series(index=['Facility','Customer'],dtype=xi.integer,manage=xi.Manage.INPUT,alias="Transport Cost") # you can also use dataframes for declaring model data '''TranportCostData: xi.DataFrame(index=['Facility','Customer'], columns=[(xi.Column("tcost",dtype=xi.integer,manage=xi.Manage.INPUT) )] )'''
- Finally, we declare result entities that will be used to display optimization model output to business users. We need Total Cost (objective function value) which is a scalar and shipment quantity from facility to customer location. In addition, we populate useful KPIs such as facility utilization and cost associated with each facility. We aggregate the optimization results and create two pandas dataframes. Entities “CostByFac” and “CapUtil” read this dataframe and create required result entities such as Total Transportation Cost (“tot_trans_cost”), Fixed Setup Cost (“FixedCost”) for opening facilities, and Total Cost (“total_cost). “CapUtil” dataframe will have shipment (“shipment”) from each facility, capacity (“Capacity”) of open facilities, and utilization (“utilization”). Note that the name of the xi.Column in your declaration should be same as the title/name of the pandas dataframe when using xi.DataFrame.
# Results need to be initialized in the run mode(s). # Entities are results if the manage attribute is xi.Manage.RESULT. Shipment: xi.Series(index=['Facility','Customer'], dtype=xi.real, manage=xi.Manage.RESULT, alias='Quantity Supplied') TotalCost: xi.Scalar(dtype=xi.real, manage=xi.Manage.RESULT, alias = "Total Cost") CostByFac: xi.DataFrame(index=['Facility'], columns=([ xi.Column("tot_trans_cost",dtype=xi.real, manage=xi.Manage.RESULT, alias="Transport Cost"), xi.Column("FixedCost",dtype=xi.integer,manage=xi.Manage.RESULT,alias = "Fixed Cost"), xi.Column("total_cost", dtype=xi.real,manage=xi.Manage.RESULT, alias = "Total Cost") ])) CapUtil: xi.DataFrame(index=['Facility'],columns = ([ xi.Column("shipment", dtype=xi.real, manage=xi.Manage.RESULT, alias = "Shipped Qty"), xi.Column("Capacity", dtype=xi.integer,manage=xi.Manage.RESULT, alias = "Capacity"), xi.Column("utilization", dtype=xi.real, manage=xi.Manage.RESULT, alias = "Utilization") ]))
This completes the declaration step. Next, we define our load and run logic.
STEP 4
Define the Load Mode: The load mode uses the decorator class @xi.ExecModeLoad. We initialize all our input entities in our Load Mode. In this example, we read the inputs from a set of CSV files: “customers.csv,” “faccost.csv”, “transportcost.csv”, and “capacity.csv”. In the latter half of this section we will show how load mode populates the values on the UI and how they can be changed by the user from the UI. We first read the files above as pandas dataframes and then use these dataframe objects to initialize the indices and series.
@xi.ExecModeLoad(descr="Loads input data.") def load(self): # Scenario is being 'loaded' through Xpress Insight. # Insight automatically populates the parameters with the values from the UI. # Input entities will be captured and stored in the scenario. # Read the customers capacity, fixed cost and transport cost files customers = pd.read_csv("customers.csv", index_col=['Customer']) # Initialize demand and set of customers self.Demand=customers['demand'] self.Customer= customers.index #Initialize fixed cost, capacity and set of facilities facility_cost = pd.read_csv(self.FacilityCostFile, index_col=['Facility']) capacity = pd.read_csv(self.CapacityFile, index_col=['Facility']) self.FixedCost= facility_cost['cost'] self.Capacity= capacity['capacity'] self.Facility=facility_cost.index # Getting in the value for transportation cost. From Facility j to customer i transportcost = pd.read_csv(self.TranspCostFile, index_col=['Facility', 'Customer']) self.TransportCost=transportcost['tcost'] print(self.TransportCost) #self.TransportCostData = pd.read_csv("transportcost.csv", index_col=['Facility', 'Customer']) print("\n Load mode finished.")
Note that input entities declared above are initialized here and referenced as self.Demand, self.Customer, etc.
STEP 5
Define Run Execution Mode: The decorator class @xi.ExecModeRun is used to define the main run mode. In case custom run modes are required to execute a separate logic/algorithm, @xi.ExecMode can be used to achieve that (please refer to Xpress Insight Python Development guide to learn more).
Here we convert input entities to list (sets) and dictionaries (parameters) and create Python objects for the objective function, decision variables, and constraints. Further, we consume the output from the solver into the pandas dataframes before we read them back into our declared result entities. The conversion of input index (Customer, Facility) to list and input series (Demand, FixedCost, and Capacity) to dictionary is done for the PuLP interface to its solvers. Here is the step-by-step of what to do:
@xi.ExecModeRun(descr="Takes input data and uses it to compute the results.") def facility_model(self): # Scenario is being 'run' through Xpress Insight. # Insight automatically populates the parameters and inputs with the values from the UI. # Result entities will be captured and stored in the scenario. print("\ building optimization problem") # Since PuLP(cbc) accepts all the sets as list, parameter and decision variables as dictionary # we will create the same from input objects as below # sets for the PuLP model CUSTOMERS = self.Customer.to_list() FACILITY = self.Facility.to_list() # parameters for the PuLP model demand=self.Demand.to_dict() fixed_cost=self.FixedCost.to_dict() throughput=self.Capacity.to_dict() transp_cost= {level: self.TransportCost.xs(level).to_dict() for level in self.TransportCost.index.levels[0]}
We then formulate the optimization model. This step will be different if you use a different Python optimization modelling library or solver API. Please refer to the documentation of your solver of choice for more details.
@xi.ExecModeRun(descr="Takes input data and uses it to compute the results.") def facility_model(self): # Scenario is being 'run' through Xpress Insight. # Insight automatically populates the parameters and inputs with the values from the UI. # Result entities will be captured and stored in the scenario. print("\ building optimization problem") # Since PuLP(cbc) accepts all the sets as list, parameter and decision variables as dictionary # we will create the same from input objects as below # sets for the PuLP model CUSTOMERS = self.Customer.to_list() FACILITY = self.Facility.to_list() # parameters for the PuLP model demand=self.Demand.to_dict() fixed_cost=self.FixedCost.to_dict() throughput=self.Capacity.to_dict() transp_cost= {level: self.TransportCost.xs(level).to_dict() for level in self.TransportCost.index.levels[0]}
After model formulation, we print some output to capture which facilities were chosen. We capture values of decision variables for shipment quantity from open facilities to customer locations. We use standard pandas data manipulation and read these dataframes to xi.DataFrame “CostByFac”, “CapUtil” and xi.Series “Shipment”.
for i in FACILITY: if use_vars[i].varValue > self.TOL: print("Establish facility at site", i) quant = [v.varValue for v in prob.variables()] quant = pd.DataFrame.from_dict({'Facility': np.tile(FACILITY, len(CUSTOMERS)), 'Customer': np.repeat(CUSTOMERS, len(FACILITY)), 'shipment': quant[:-3]}) cost_cap = quant quant=quant.set_index(['Facility','Customer']) quant = quant[quant['shipment'] > 0] self.Shipment=quant['shipment'] TransportCost = self.TransportCost.to_frame().reset_index() FixedCost = self.FixedCost.to_frame().reset_index() Capacity = self.Capacity.to_frame().reset_index() cost_cap = cost_cap.merge(TransportCost) cost_cap = cost_cap.merge(FixedCost) cost_cap = cost_cap.merge(Capacity) cost_cap = cost_cap[cost_cap['shipment']>0] cost_by_fac = cost_cap.loc[:,['Facility','shipment','TransportCost','FixedCost']] cap_util = cost_cap.loc[:, ['Facility','shipment','Capacity']] cost_by_fac['tot_trans_cost'] = cost_by_fac['shipment']*cost_by_fac['TransportCost'] cost_by_fac=cost_by_fac.groupby(['Facility'])['tot_trans_cost','FixedCost'] \ .agg({ 'tot_trans_cost' : 'sum', 'FixedCost' : 'mean' }) cost_by_fac['total_cost'] = cost_by_fac['tot_trans_cost'] + cost_by_fac['FixedCost'] cap_util = cap_util.groupby(['Facility'])['shipment','Capacity'] \ .agg({ 'shipment' : 'sum', 'Capacity' : 'mean' }) cap_util['utilization'] = cap_util['shipment']/cap_util['Capacity'] self.CostByFac = cost_by_fac self.CapUtil = cap_util self.TotalCost=value(prob.objective)
This completes our example on configuring Python models and set of steps to take to make your Python model compatible with FICO Xpress Insight requirements.
3. Creating Custom Views with View Designer
Overview
Xpress Insight's capabilities can be augmented by the addition of custom views for rich, interactive interfaces specific to a particular application. There are three methods for adding custom views:
- Drag and drop app development using View Designer (based on View Definition Language), with seamless code-view switch
- JavaScript APIs
- Tableau for FICO
We will focus on creating custom Insight app views with View Designer, a built-in component of FICO Xpress Workbench. The View Designer enables rapid development of custom interactive views by drag and drop actions. It allows you to associate user interface components with model data for viewing and editing. Views are created in XML notation and can contain any valid HTML markup, along with additional elements defined by the VDL language. The View Designer creates this VDL code, which is an extensible markup language that allows you to create reusable components.
Solution Developers can select appropriate elements from the Palette to build custom view layouts with tables and forms that contain model data. Upon selecting the right element within the View Designer artboard, the associated attributes will appear in the Attributes pane (which is on the right-hand side) where solution developers can style and rename columns, tables, table columns and forms. The layout of VDL views can be configued by using columns and rows. Columns have a horizontal size and devide a row into vertical blocks. Each row can hold up to 12 columns, including offsets. You can read more about editing view layouts here.
More advanced users can switch between the View Designer and code view to edit VDL source code and to add custom JavaScript, if needed.
After modifying your Python file, here are the steps to create custom views for your Insight application:
Add a New View Under a New View Group Named Control Panel
STEP 1
From File -> New, select Insight VDL View:
STEP 2
Rename the View Title to Control Panel and Change Filename to control-panel.vdl. And, from View Group field, select Create a new view group and rename the view group Model Settings.
STEP 3
Click Finish or Next and choose basic view and proceed to next tab where you can choose the default number of columns and other parameters for your view. Once finished, you will see a tab in Workbench like below:
Add Demand Table with a Table Name
STEP 1
From the Palette, drag and drop Table component into a Column section of the View Designer artboard. Select the Demand entity in Table wizard and press Next. Under Customize, check the Editable checkbox and click Finish.
STEP 2
Finally, to name the column that contains your table, click on the Column section and change Heading to Demand Table and adjust the Heading level to 4 and Column Size to 6 with Offset set to zero. Note that the layout of an Insight view can be configured by using columns and rows. Columns divide a row into vertical blocks. You can read more about editing view layouts here.
You can also use the Duplicate button on any selected object in your View Designer artboard area to duplicate the content of that section. Similarly, you can move the selected objects using the re-order buttons.
STEP 3
Next Select the Table Section from the View Designer artboard (1) to access the table's associated attributes on the Attributes pane (2). Check Column filter, Search and choose paged from the Pagination field with Page size set to the value of your choice and publish your new Control Panel view to Insight (3).
STEP 4
After the Insight app is published successfully, go to your Insight app and browse your view. Load and modify input values to run a new scenario. Note that each view group can contain several views. You can use multiple view groups to create a better user experience.
STEP 5
You can filter your table and search for specific values within your table and browse through multiple pages of your table based on the page size setting you selected from the Attributes pane.
Configure Demand Table as Multi-Scenario
STEP 1
Xpress Insight offers scenario analysis capabilities. Views that show input or results data of multiple scenarios side-by-side enables users to quickly understand the difference between multiple what-if results. To make your table multi-scenario for side-by-side comparisons, drag the Repeat component from the Logic section of the Palette and place it on your Table Column. When Repeat Wizard is prompted, select Repeat a table column for each scenario on the shelf.
STEP 2
Next, on the table column Attribute pane, type =i under scenario and change the Heading to =’Demand - ’ + s.props.name. This will enable your table to show demand entity values for scenarios that are placed on the shelf and display the name of the associated scenario as the table column header.
STEP 3
To test this functionality, clone Scenario 1, rename it Scenario 2, and place both scenarios on the scenario shelf (grey bar).
STEP 4
To format your values to a single digit number select your Table Column and under the Table Column attributes pane change the value of the Format field to your desired format. For more information on formatting features please review the tooltip of the Format field.
STEP 5
Similarly, to have your sets sorted in a direction that differs from the default you can use the Set Sorter in the Palette pane. Simply place it in your View Designer page section area and type in your Comparator and choose Direction and the Set from the associated fields in Set Sorter Attributes pane.
Add a Form: Total Cost
STEP 1
From the Palette, drag a Form component into a Column section on the artboard. Next drag a Field component into your Form. To make this field multi-scenario, drag and drop Repeat on associated column. Next, select your Field and from the attributes pane for Field, type in =’Total Cost ’ + s.props.name in the Label field and =i in the Scenario field. Finally, select TotalCost from the Entity field. You can now optionally adjust the Label size and Size of your field.
Add a Simple Chart (Multi-Scenario)
STEP 1
From the Palette section, drag and drop a Chart component into a Column section of View Designer. Select the Demand entity from Chart wizard, click Finish and manually drag and drop a Chart Series component into your Chart section. Next, on the Chart Series Attributes pane, select your Shipped Qty from the Entity field and then specify the type of chart you would like to create in the Type field (pie chart in this case).
STEP 2
To make this report multi-scenario, drag Repeat from the Palettes and place it on the parent Column section of your Chart. When Repeat wizard is prompted select Repeat a column for each scenario of the shelf, select your Chart Series attributes pane, and type in =i in Scenario field. For cosmetic purposes, set the size of the parent column to be 6 and add the scenario name =Supply Share - ' + s.props.name to the Heading field of the column attributes pane. Now change the demand value for Customer 1 to 180 and re-run your scenario. Here are how your results will look like in your Insight application view.
Add Button to Load Default Data
STEP 1
Drag and drop Action from the Actions section of the Palette. Select the action group and change the name to LoadMode from Attributes pane.
STEP 2
Drag Execute Model from the Actions section of the Palette pane and place it into your LoadMode action group. Change the Mode to Load from Execute Model attributes pane on the right-hand side.
STEP 3
Next, drag and drop Container from your Palette and a column section of within your View Designer. Drag and drop a Button from components into your Container section. Select the Button and change the Label to Load Default Data from the Attributes pane. Finally, select Add Event from the Events section, choose click from Event field dropdown, and select the LoadMode under Action Group field dropdown.
STEP 4
Next, publish your app and review from your Insight app view.
Add Run Model Button
STEP 1
Drag Execute Model from Actions section of the Palette pane and place it onto your View Designer artboard. Change the Mode to Run from the Execute Model attributes pane on the right-hand side. Select the action group and change the name to RunMode from Attributes pane. Then, drag and drop Button from components into a column section of your View Designer. Select the Button and change the Label to Run Model from Attributes pane. Finally, select Add Event from Events section, choose click from Event field dropdown, and select the RunMode under Action Group field dropdown.
Here is how your final View will look:
Note: The purpose of this content is to provide an example for Python users new to FICO Xpress Optimization for building simple Insight Python applications. Other examples such as Getting Started (Quick Start) guide and another basic Insight app can be found in the Insight Developers Guide for Python here.
4. Xpress Installation and Python Setup
Installing FICO Xpress Optimization is comprised of two steps. First you need to install Xpress (which comes with Xpress Solver and Xpress Workbench) and then you should install FICO Xpress Insight. After FICO Xpress Optimization installation, you should link your Python installation to your Xpress Insight installation.
Install FICO Xpress
STEP 1
Obtain the FICO® Xpress software installer - the file xpX.Y_win_x86_64_setup.exe, where X and Y are version numbers (you can download the Xpress community version here).
STEP 2
Run the setup file.
STEP 3
If you are a Symantec user, click Allow this file to proceed.
STEP 4
Select Community License (or Static Licensing if you own a commercial license of Xpress).
STEP 5
Click No for hardware dongle support.
STEP 6
Click No for Kalis support.
STEP 7
Accept all the other default settings to complete the installation.
STEP 8
Important: If you are prompted to restart your machine, click No.
STEP 9
If you own a commercial license of Xpress, copy your license file xpauth.xpr to <installationdir>\bin.
You can now go on to install Xpress Insight as described in the next section.
Install FICO Xpress Insight
STEP 10
Check your Java version (from command prompt run “java - version”). If your version matches the highlighted, then go to go to next step, otherwise install Java 11. We recommend Amazon Corretto 11).
STEP 11
Obtain FICO Xpress Insight Installer (version 4.53).
STEP 12
Run setup file.
STEP 13
Select default installation (C:\xpressmp – same directory as Xpress installation).
STEP 14
Select all components on Custom Setup page.
STEP 15
Accept localhost default.
STEP 16
If you own a commercial license of Xpress, you can optionally install tableau for FICO. You can find information on how to install Tableau here.
Link Python Installation to FICO Xpress Optimization
For the sake of brevity, only the major steps are highlighted. We recommend you read the "Installation and Setup" section in the Insight Python reference guide.
STEP 17
Python Version 3.7.x + .
STEP 18
Install Python to your system path variable – Setting user (instead of system) variable only is not sufficient; Xpress Insight won't be able to execute Python.
STEP 19
Do a pip or conda install of xpressinsight.
STEP 20
Change your MOSEL_RESTR to zero from your xprmsrv.cfg under …/xpressmp/bin folder (MOSEL_RESTR=0); please, read the guide for details on security implications and further optional adjustments.
STEP 21
Restart FICO Execution Worker from Services (from Windows Start menu search Services).
For the detailed installation guide, please refer to Xpress Installation Document here.
Updated 1 year ago
Version 5.0No CommentsBe the first to comment