Introduction to PIFOP Functions

PIFOP Functions is an experimental feature. Contact us if you would like to try it out.

Turn your Optimization Models into Web Services

PIFOP Functions is a new way of deploying mathematical optimization models to the cloud. It allows you to make your optimization programs (models, scripts, etc) executable from virtually any application, including Excel for the web, Google Sheets, your company's internal system and your client's website.

This wide-ranging integration capability is achieved by turning your optimization models into web services accessible via a REST API, which is what a PIFOP Function is.

Key Features

  1. Integration-ready: when a Function is created, it is immediatelly ready to be called via APIs and client libraries.
  2. Offer the solution without giving away the secret: callers of Functions developed by you have no access to the underlying optimization model.
  3. Any kind of project can be deployed as a Function: AMPL, GAMS, Python, C/C++, and more.
  4. Access control is in your hands: Functions require API keys to be used, which are generated and managed by you.

Use Cases

  1. Black-box consulting solutions: create optimization solutions for your clients without exposing the model behind it.
  2. One solution for many clients: create a single optimization solution and offer it to multiple of your clients.
  3. Extend existing applications with math optimization: integrate Functions into your company's internal systems and other applications.
  4. Create optimization-based plugins for popular applications: many applications that are widely used by your clients can be extended via plugins, such as Excel for the web and Google Sheets. PIFOP Functions makes it easier for you to develop and offer optimization-based plugins.

Simple Example: TSP Solver

This project implements an optimization model in AMPL to solve the Traveling Salesman Problem (TSP). We have deployed it as a PIFOP Function, and we are using it as the calculation backend for a demo web application.

Function Implemetation

This is the AMPL script that is executed when the Function is called:

# Implementation of the MTZ formulation of the TSP #-------------------------------------------------- param n; set V := 1..n; param x{V}; param y{V}; set E dimen 2 := {i in V, j in V : i != j}; param c{(i,j) in E}; var w{(i,j) in E} binary; var u{i in V : i >= 2} integer >= 1, <= n-1; minimize z : sum{(i,j) in E} c[i,j] * w[i,j]; subject to c2{i in V} : sum{(i,j) in E} w[i,j] = 1; c3{j in V} : sum{(i,j) in E} w[i,j] = 1; c4{(i,j) in E: i >= 2 and j >= 2} : u[i]-u[j] + (n-1)*w[i,j] <= n-2; # Read caller's input #--------------------- data coords.dat; # Calculate edge costs #---------------------- let{(i,j) in E} c[i,j] := sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2); # Solve with CPLEX #------------------ option solver cplex; solve; # Get optimal route #------------------- param route{1..n}; param aux; let route[1] := 1; let aux := 1; for {i in 2..n} { for {j in 1..n : aux != j} { if w[aux,j] = 1 then { let route[i] := j; break; } } let aux := route[i]; } # Write result.json #------------------- printf "{\n ""route"": [1">result.json; printf{i in 2..n} ", %d", route[i] >result.json; printf "],\n">result.json; printf " ""length"": %.4f\n", z.val >result.json; printf "}">result.json;

Function Input and Output

Note that the above script reads the node coordinates from a file called coords.dat, which does not exist in the project itself. This file is supposed to be submitted by the caller of the Function, as specified by the "input" property in the Function configuration file.

Note also that the script writes the output to a file called result.json. This file can be downloaded by the caller of the Function after the execution is finished, as specified by the "output" property in the Function configuration file.

Function Configuration File

The func.json file is a Function configuration file. Among other things, here we define the Function id, the command that should be executed when the Function is called, the input files that it expects from the user and the output files it generates for the user:

{ "id": "tsp-demo", "name": "TSP Demo", "description": "Solves TSPs using the MTZ formulation", "command": "ampl tsp.mod", "input": [ { "id": "coords", "path": "coords.dat" } ], "output": [ { "id": "result", "path": "result.json" } ] }

Calling the Function from a Web Application

We use the PIFOP Functions JavaScript client API to call the TSP Function from the demo web application.

Here is a snippet of the code that calls the Function and displays the result:

const apiKey = "apikey_6qOZPWTGfF7AcKcRhxEnvGkuGE8YkIdesHecUlCUhXNSsAau"; pifop.execute("PIFOP/tsp-demo", apiKey, coordsInput) .onFinish((execution) => { // Display the solution returned at execution.result });

The entire source code for the web application can be found here.

Terms and Privacy Help Pricing About Blog Contact us Server Status Twitter LinkedIn