Object Oriented GAMS API:

Similar documents
for Algebraic Modeling Systems?

Multimodal Coal Transportation Model

Contents. 9-1 Copyright (c) N. Afshartous

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

See the Developer s Getting Started Guide for an introduction to My Docs Online Secure File Delivery and how to use it programmatically.

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

2009 Tutorial (DB4O and Visual Studio 2008 Express)

Introduction to Object-Oriented Programming

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

GAMS, Condor and the Grid: Solving Hard Optimization Models in Parallel. Michael C. Ferris University of Wisconsin

Part I. Multiple Choice Questions (2 points each):

Building Java Programs

JAVA ARRAY EXAMPLE PDF

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

CPLEX Tutorial Handout

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

CSCI 3136 Principles of Programming Languages

Advanced Java Client API

CMSC 202H. ArrayList, Multidimensional Arrays

Sample CSE8A midterm Multiple Choice (circle one)

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Web Services API Developer Guide

Introduction to Java

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Introduction to programming

Networks and Services

CHAPTER 10: WEB SERVICES

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Arrays in Java. Working with Arrays

Building Java Programs

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Computational Mathematics with Python

Unit 6. Loop statements

(Eng. Hayam Reda Seireg) Sheet Java

Collections.sort(population); // Método de ordenamiento

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

This explanations are for absolute beginners. Skilled programmers should (and probably will) use more effective approach.

Comp 248 Introduction to Programming

Introduction to Object-Oriented Programming

1. Overview. 2. Requirements

Moving from CS 61A Scheme to CS 61B Java

Introduction to Linear Programming (LP) Mathematical Programming (MP) Concept

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

A Study of Software as a Service Business Model

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Building Java Programs

CS170 Lab 11 Abstract Data Types & Objects

Functional Programming in C++11

Object Oriented Software Design

Computational Mathematics with Python

Computational Mathematics with Python

Effective unit testing with JUnit

CS106A, Stanford Handout #38. Strings and Chars

Using EDA Databases: Milkyway & OpenAccess

Programmierpraktikum

Java Web Services SDK

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

The C Programming Language course syllabus associate level

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

GAMS Productivity - Performance - Reliability

Monitor Your Key Performance Indicators using WSO2 Business Activity Monitor

Chapter 2 Introduction to Java programming

Consuming a Web Service(SOAP and RESTful) in Java. Cheat Sheet For Consuming Services in Java

Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value

Take Your Team Mobile with Xamarin

Software Development with UML and Java 2 SDJ I2, Spring 2010

Java Programming Fundamentals

Introducing the.net Framework 4.0

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Logging in Java Applications

AP Computer Science Java Subset

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

.NET Overview. Andreas Schabus Academic Relations Microsoft Österreich GmbH

Continuous Integration Part 2

WebSphere Business Monitor

Java Application Developer Certificate Program Competencies

The power of IBM SPSS Statistics and R together

More on Objects and Classes

Crash Course in Java

public static void main(string[] args) { System.out.println("hello, world"); } }

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

ACE 2011 International

Programming Languages CIS 443

Alternatives to SNMP and Challenges in Management Protocols. Communication Systems Seminar Talk 10 Francesco Luminati

Amazon Glacier. Developer Guide API Version

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Programming and Software Development CTAG Alignments

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Onset Computer Corporation

Interactive Applications (CLI) and Math

Web Applications Testing

The separation principle : a principle for programming language design

Generating Automated Test Scripts for AltioLive using QF Test

Transcription:

Object Oriented GAMS API: Java, Python and.net Clemens Westphal cwestphal@gams.com GAMS Software GmbH GAMS Development Corporation www.gams.com www.gams.com Rotterdam, September 5, 2013

Outline Introduction Seamless Integration Small example in C#, Java and Python Scenario Solving Simple Encapsulation of a GAMS Model 2

Calling GAMS from your Application Application GAMS GDX SOLVER Creating Input for GAMS Model Data handling using GDX API Callout to GAMS GAMS option settings using Option API Starting GAMS using GAMS API Reading Solution from GAMS Model Data handling using GDX API 3

Low level APIs object oriented API Low level APIs GDX, OPT, GAMSX, GMO, High performance and flexibility Automatically generated imperative APIs for several languages (C, Delphi, Java, Python, C#, ) Object-oriented GAMS API Additional layer on top of the low level APIs Object-oriented Written by hand to meet the specific requirements of different object-oriented languages 4

Features of the object oriented API No modeling capability. Model is still written in GAMS Prepare input data and retrieve results in a convenient way GAMSDatabase Control GAMS execution GAMSJob Seamless integration of GAMS into other programming environments 5 Scenario Solving: Feature to solve multiple very similar models in a dynamic and efficient way. GAMSModelInstance

Seamless Integration GAMS concept: Separation of tasks APIs Tools GDX GAMS Solver Use GAMS for modeling and optimization tasks Programming languages like C# (.NET), Java and Python are wellsuited for developing applications (GUI, Web, ) frameworks available for a wide range of specific task: GUI and Web development, 6 The object oriented GAMS API provides a convenient link to run GAMS in such environments

Seamless Integration Example: Small transport Desktop application written in C# Convenient data preparation Representation of the results in a predefined way Modeling details are hidden from the user 7

Small Example - C# Transport.cs using System; using GAMS; namespace TransportSeq class Transport1 static void Main(string[] args) GAMSWorkspace ws = new GAMSWorkspace(); GAMSJob t1 = ws.addjobfromstring(getmodeltext()) t1.run(); foreach (GAMSVariableRecord rec in t1.outdb.getvariable("x")) Console.WriteLine("x(" + rec.keys[0] + "," + rec.keys[1] + "):"); Console.WriteLine(" level=" + rec.level); Console.WriteLine(" marginal=" + rec.marginal); 8

Small Example - C# static String GetModelText() String model = @" Sets i canning plants / seattle, san-diego / j markets / new-york, chicago, topeka / ; Parameters a(i) capacity of plant i in cases / seattle 350 san-diego 600 / b(j) demand at market j in cases / new-york 325 chicago 300 topeka 275 / ; <... > Solve transport using lp minimizing z ;"; 9 return model;

Small Example - Java Transport.java package TransportSeq; import com.gams.api.* class Transport1 static void main(string[] args) GAMSWorkspace ws = new GAMSWorkspace(); GAMSJob t1 = ws.addjobfromstring(getmodeltext()); t1.run(); for (GAMSVariableRecord rec : t1.outdb().getvariable("x")) System.out.println("x(" + rec.getkeys()[0] + ", " + rec.getkeys()[1] + "):"); System.out.println(" level =" + rec.getlevel()); System.out.println(" marginal =" + rec.getmarginal()); 10

Small Example - Python transport.py from gams import * if name == " main ": ws = GamsWorkspace() t1 = ws.add_job_from_string(get_model_text()) t1.run() for rec in t1.out_db["x"]: print rec 11

Scenario Solving - Loop Loop(s, f = ff(s); solve mymodel min z using lp; objrep(s) = z.l; ); Data exchange between solves possible Model rim can change Each solve needs to regenerate the model 12 User updates GAMS Symbols instead of matrix coefficients

Scenario Solving - GUSS set dict / s.scenario.'' f.param.ff z.level.objrep / solve mymodel min z using lp scenario dict; Save model generation and solver setup time Hot start (keep the model hot inside the solver and use solver s best update and restart mechanism) Apriori knowledge of all scenario data 13 Model rim unchanged from scenario to scenario

Scenario Solving - GAMSModelInstance foreach (string s in scen) f.firstrecord().value = v[s]; modelinstance.solve(); objrep[s] = z.firstrecord().level; Save model generation and solver setup time Hot start (keep the model hot inside the solver and use solver s best update and restart mechanism) Data exchange between solves possible 14 Model rim unchanged from scenario to scenario

GAMSModelInstance - Example bmult is one parameter of the model which gets modified before we solve the instance: GAMSParameter bmult = mi.syncdb.addparameter("bmult", 0, "demand multiplier"); bmult.addrecord().value = 1.0; mi.instantiate("transport us lp min z", opt, new GAMSModifier(bmult)); double[] bmultlist = new double[] 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 ; foreach (double b in bmultlist) bmult.firstrecord().value = b; mi.solve(); <...> Console.WriteLine(" Obj: " + mi.syncdb.getvariable("z").findrecord().level); 15

GAMSModelInstance - Example Updating bounds of a variable: GAMSVariable x = mi.syncdb.addvariable("x", 2, VarType.Positive, ""); GAMSParameter xup = mi.syncdb.addparameter("xup", 2, "upper bound on x"); mi.instantiate("transport us lp min z", modifiers: new GAMSModifier(x,UpdateAction.Upper,xup)); foreach (GAMSSetRecord i in t7.outdb.getset("i")) foreach (GAMSSetRecord j in t7.outdb.getset("j")) xup.clear(); xup.addrecord(i.keys[0],j.keys[0]).value = 0; mi.solve(); <...> Console.WriteLine(" Obj: " + mi.syncdb.getvariable("z").findrecord().level); 16

Simple Encapsulation of a GAMS Model Wrapper class that encapsulates a single GAMS model Very simple interface: Properties to communicate input data and results Property to change options like the solver to use Run() method to run the model Most implementation details are hidden in the wrapper class Highest level of abstraction (that is useful): Data exchange, options, run() 19

Simple Encapsulation of a GAMS Model Wrapper Class GAMS Model (source) Data/Results Options Run() Main Program 20

Simple Encapsulation of a GAMS Model... GAMSWorkspace ws = new GAMSWorkspace(); Transport t = new Transport(ws); foreach (string p in plants) t.i.addrecord(p); foreach (string m in markets) t.j.addrecord(m); foreach (string p in plants) t.a.addrecord(p).value = capacity[p]; foreach (string m in markets) t.b.addrecord(m).value = demand[m];... t.opt.allmodeltypes = "Gurobi"; t.run(output: Console.Out); Console.WriteLine("Objective: " + t.z.firstrecord().level); foreach (GAMSVariableRecord rec in t.x) Console.WriteLine("x(" + rec.keys[0] + "," + rec.keys[1] + "): level=" + rec.level + " marginal=" + rec.marginal); 21

Summary Object Oriented API provides an additional abstraction layer on top of the low level GAMS APIs Powerful and convenient link to other programming languages.net, Java and Python APIs are part of the current GAMS release available at www.gams.com. Many examples available: Sequence of Transport examples Cutstock, Warehouse, Benders Decomposition 22.NET/Mono and C++ under development

Contacting GAMS Europe GAMS Software GmbH P.O. Box 40 59 50216 Frechen Germany Phone: +49 221 949 9170 Fax: +49 221 949 9171 info@gams.de USA GAMS Development Corp. 1217 Potomac Street, NW Washington, DC 20007 USA Phone: +1 202 342 0180 Fax: +1 202 342 0181 sales@gams.com support@gams.com 23 http://www.gams.com