西江河畔分享 http://blog.sciencenet.cn/u/qhhuangscut 专注电力系统研究,对信息技术和系统科学的应用感兴趣。

博文

InterPSS-GAMS整合进行电力系统运行优化与分析的简单例子

已有 6346 次阅读 2013-4-24 16:16 |个人分类:InterPSS|系统分类:科研笔记| 电力优化InterPSSGAMS

Introduction to InerPSS-GAMS Integration


The purpose of this introduction-level document is to introduce GAMS ,specially the new Java API introduced in  V24.0, provide some guidance, including sample code, for InterPSS and GAMS integration.

1.1 GAMS 24.0

The General Algebraic Modeling System (GAMS) is a high-level modeling system for mathematical programming and optimization. It consists of a language compiler and a stable of integrated high-performance solvers. GAMS is tailored for complex, large scale modeling applications, and allows you to build large maintainable models that can be adapted quickly to new situations.

For details, http://www.gams.com/

(1) Overview of GAMS new API  

 

The object-oriented GAMS API allows the seamless integration of GAMS into anapplication by providing appropriate classes for the interaction with GAMS. TheGAMSDatabase class for in-memory representation of data can beused for convenient exchange of input data and model results. Models written inGAMS can be run with the GAMSJob class and by using the GAMSModelInstance class a sequence of closely related model instances can be solved in the most efficient way. There are three versions of the object-oriented GAMS API: Java,Python and .NET. These APIs work with Java SE 5 and up, Python2.7, and .NET framework 4 (Visual Studio 2010) and up.

For details: see http://www.gams.com/dd/docs/api/

(2) Installation

1. Download from GAMSdownload webside, X86 32bit, V24.0.2  is used when preparing  this document.

2. When installing the GAMS, make sure choose "add the install dir to the system environment".

1.2. Call GAMS from Java

Since v24.0, new GAMSJava APIs introduce the following concepts/classes, allowing better integration with Java-based projects.

  • GAMSWorkspace     : Workspace in  Java environment which has most of the functions in the native GAMS     workspace. To Integrate GAMS in any Java project, first we need to create  an GAMSWork space, as follows

         GAMSWorkspace ws = newGAMSWorkspace();

 

         Then we can use ws to create database

                GAMSDatabase db =ws.addDatabase();

          andcreate GAMSJob:

                GAMSJob ieee14ED =ws.addJobFromString(modelStr);

  • GAMSDatabase: storing and processing the modeling data in in-momory     database

  • GAMSSet and GAMSParameter: Base     data set for storing the indices and modeling data, respectively.

          Example:

           GAMSSet loadBus = db.addSet("j", 1,"load buses");

           GAMSParametergenPLow = db.addParameter("genPLow", 1,"lower bound of eachgenerating unit");

  • GAMSVariableRecord: Get the optimization results directly from the database

          Example:

        for (GAMSVariableRecord rec :ieee14ED.OutDB().getVariable("genp")){

          System.out.println("genP@ Bus-" + rec.getKeys()[0]+"  : Level=" + rec.getLevel() );

         }

  • GAMSJob: Now we can create GAMSJob from modeling String, no     independent “*.gms” modeling file is needed.

          Example:

           GAMSJob ieee14ED = ws.addJobFromString(modelStr);


     The GAMS Java Library GAMSJavaAPI.jarcan be found under thefolder:  

               <Path to GAMS>apifilesJavaapi

     (Corresponding DLLs can also be found under this folder). This has been add to the ipss.lib.3rdPty/gams


Note:

1. The order of library(seems) matters

The GAMSJAVAAPI.jar shouldput at the top order of the project (It was found GAMS issued compile error when this jar was put at the last), therefore the following order is recommended for the path configuration.




2. GAMS Related class runconfiguration setting within Eclipse

    Run the class by run->runconfiguration…->setting the VM arguments as follows:

              -Djava.library.path="<GAMS Install Dir>\apifiles\Java\api"

 


Which guarantees thatthe required DLLs are accessible/visible from the class.

1.3  ED Sample

IEEE14Bus Economicdispatch:

https://code.google.com/p/interpss/source/browse/trunk/ipss.gams.test/src/test/ed/Ieee14EdWithGAMS24.java


To run the sample, threeInterPSS projects are required, they are:



Make sure you have checked out at least these three projects from InterPSS Google Repo( https://code.google.com/p/interpss/) to run the sampe testcase—Ieee14EdWithGAMS24.java,which is under the “test.ed“ package.

 

Result:

----------------------------------------------------------------------------------------------

genP @ Bus-Bus1  :level=1.91 ,  marginal=0.0

genP @ Bus-Bus2  :level=0.5 ,  marginal=-20.033200000000004

genP @ Bus-Bus3  :level=0.05 ,  marginal=39.96479999999998

genP @ Bus-Bus4  :level=0.0 ,  marginal=-30.038200000000003

genP @ Bus-Bus5  :level=0.0 ,  marginal=-30.038200000000003

genP @ Bus-Bus6  :level=0.06 ,  marginal=19.968999999999994

genP @ Bus-Bus7  :level=0.0 ,  marginal=-30.038200000000003

genP @ Bus-Bus8  :level=0.07 ,  marginal=9.974400000000003

genP @ Bus-Bus9  :level=0.0 ,  marginal=-30.038200000000003

genP @ Bus-Bus10  :level=0.0 ,  marginal=-30.038200000000003

genP @ Bus-Bus11  :level=0.0 ,  marginal=-30.038200000000003

genP @ Bus-Bus12  :level=0.0 ,  marginal=-30.038200000000003

genP @ Bus-Bus13  :level=0.0 ,  marginal=-30.038200000000003

genP@ Bus-Bus14  : level=0.0 ,  marginal=-30.038200000000003




https://blog.sciencenet.cn/blog-405788-683574.html

上一篇:Power system open software/toolbox
下一篇:MinGW与EGCS冲突
收藏 IP: 68.98.21.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

全部作者的精选博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-16 00:03

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部