Optimization PeopleCode

This chapter discusses how to:

Important! The optimization PeopleCode classes are not supported on IBM z/OS and Linux for IBM System z platforms.

Click to jump to parent topicUsing Optimization PeopleCode on the Application Server

While running optimization PeopleCode on the application server, ensure that changed data is committed to the database before calling the CreateOptEngine optimization function and the following OptEngine class methods:

Note. The PeopleCode functions CommitWork and DoSaveNow can be called within a step to save uncommitted data to the database before calling the listed functions and methods. Keep in mind that forcing a commit on pending database updates is a serious step; it prevents roll-back on error. CreateOptEngine, ShutDown, InsertOptProbInst, and DeleteOptProbInst calls modify the database, so take care when terminating the Application Engine program without committing the changes made by those calls.

Click to jump to parent topicUsing Optimization PeopleCode in an Application Engine Program

When you write an optimization PeopleCode program in an Application Engine program and you schedule it in PeopleSoft Process Scheduler, you must set the process definition with a process type of Optimization Engine. Other process types do not allow optimization PeopleCode in Application Engine programs.

While using optimization PeopleCode in Application Engine programs, make sure data is committed before calling the CreateOptEngine optimization function and the following OptEngine class methods:

Note. You can call the PeopleCode functions CommitWork and DoSaveNow within a step to save uncommitted data to the database before calling the listed functions and class methods. Keep in mind that forcing a commit on pending database updates is a serious step; it prevents roll-back on error. CreateOptEngine, ShutDown, InsertOptProbInst, and DeleteOptProbInst calls modify the database, so take care when terminating the Application Engine program without committing the changes made by those calls.

Click to jump to parent topicPerforming Optimization in PeopleCode

This section discusses how to:

Click to jump to top of pageClick to jump to parent topicCreating New Analytic Instances

To create a new analytic instance for an analytic type:

  1. Call the function InsertOptProbInst with the analytic type and analytic instance as parameters to create an analytic instance ID.

  2. Use Application Engine or a similar mechanism to load the optimization application tables with data.

    Use the analytic instance ID as the key value in scenario-managed optimization application tables.

    The analytic instance is now ready to be loaded into an analytic server.

Note. You can load multiple copies of the same analytic instance into multiple instances of an analytic server, provided that each instance of the analytic server resides in a different application server domain. Each analytic instance loaded into a given domain must be unique. Within a given domain, you cannot have the same analytic instance in more than one analytic server. The analytic server maintains data integrity by checking to see if the data has been altered by another user (refer to the steps in the optimization system architecture description). Try to maintain data consistency when the same analytic instance uses the same database in different domains.

See Also

PeopleSoft Optimization Framework System Architecture

InsertOptProbInst

Click to jump to top of pageClick to jump to parent topicLoading Analytic Instances Into an Analytic Server

Use the CreateOptEngine function to load an analytic server with an analytic instance. It takes analytic instance ID and a mode parameter with %Synch and %Asynch as possible values and returns a PeopleCode object of type OptEngine.

You can run the PeopleCode on the application server or from Application Engine.

Loading Analytic Instances by Running PeopleCode on the Application Server

To block PeopleCode from running on the application server until the load is done (synchronous mode), use the %Synch value for the mode parameter. An error is generated if the load isn't successful. The application server imposes a timeout beyond which the PeopleCode and optimization engine load are terminated. Here is a code example:

Local OptEngine &myopt; &myopt = CreateOptEngine("PATSMITH", %Synch);

To load the analytic server without blocking the PeopleCode from running (asynchronous mode) on the application server, use the %Asynch value for the mode parameter. The analytic server performs a preliminary check of the load request and returns the OptEngine object if it is successful or an error if it is unsuccessful. A successful return does not mean that the load was successful. You must then use repeated CheckOptEngineStatus methods on the returned OptEngine object to determine whether the analytic engine is done with the load and whether it was successful. Here is a code example:

Local OptEngine &myopt; &myopt = CreateOptEngine("PATSMITH", %Asynch);

Loading Analytic Instances by Running PeopleCode in Application Engine

Both synchronous (%Synch) and asynchronous (%Asynch) modes block the PeopleCode from running on Application Engine until the load is done. Use only %Asynch while loading an optimization engine.

The absolute number of optimization engine instances that may be loaded in a given domain is governed by a configuration file loaded by Tuxedo during its domain startup.

See Also

CheckOptEngineStatus

Administering Optimization Server Components

Click to jump to top of pageClick to jump to parent topicRunning Optimization Transactions

You send an optimization transaction to the optimization engine using the RunSynch and RunAsynch methods. Both are methods on an OptEngine object. The OptEngine object can be created either by calling CreateOptEngine (if the optimization engine is not loaded already) or by calling GetOptEngine (if the optimization engine is already loaded). Both RunSynch and RunAsynch have the same signature, except that RunSynch runs the optimization transaction in synchronous mode and RunAsynch runs it in asynchronous mode. Both return an integer status code. You can run transactions either on the application server or with Application Engine.

To invoke an optimization transaction:

  1. Use the GetOptEngine function to get the OptEngine object as a handle for the optimization engine that has loaded an analytic instance ID.

    Use the CreateOptEngine function to create the OptEngine object for a new optimization engine if the analytic instance has not been loaded.

  2. Call RunSynch or RunAsynch to send an optimization transaction to the optimization engine to be run in synchronous or asynchronous mode.

  3. If the transaction is run in synchronous mode (RunSynch), use the OptEngine methods GetString, GetNumber, and so on, to retrieve the output result from the optimization transaction.

    The transaction names, parameter names, and data types are viewable in the analytic type in Application Designer.

  4. If the transaction is run in asynchronous mode, use the OptEngine method CheckOptEngineStatus to check the status of the optimization transaction in the optimization engine.

    After the transaction is done, result data is available in the database for retrieval using standard PeopleCode mechanisms.

Running Optimization Transactions from the Application Server

To block the PeopleCode from running on the application server until the optimization transaction is done (synchronous mode) and receives the results, use RunSynch to send an optimization transaction. An error status code is returned if the transaction isn't successful. If successful, you can use other methods to retrieve the results from the transaction call. The application server imposes a timeout beyond which the PeopleCode and optimization engine transaction are terminated.

To run a transaction without blocking PeopleCode from running (asynchronous mode) on the application server, use RunAsynch to send an optimization transaction. In this mode, the optimization engine performs a preliminary check of the transaction request and returns a success or failure status code. A successful return does not mean that the transaction is successful; it means only that the syntax is correct. You must then use repeated calls to the CheckOptEngineStatus method on the OptEngine object to determine whether the optimization engine is done with the transaction and whether it is successful.

RunAsynch does not allow transaction output results to be returned. Use this method for long-running transactions that return results entirely through the database.

Running Optimization Transactions from Application Engine

Both synchronous (RunSynch) and asynchronous (RunAsynch) methods block the PeopleCode from running on Application Engine until the optimization transaction is done. RunSynch allows output results to be returned, but it should be used for transactions that are fast (less than 10 seconds). RunAsynch does not have a time limit, but it does not return output results.

See Also

RunAsynch

Click to jump to top of pageClick to jump to parent topicInvoking the Optimization PeopleCode Plug-In

If you're developing an optimization application that uses the Optimization PeopleCode plug-in, you must do the following to invoke the plug-in:

See Also

Creating Analytic Type Definitions

CreateOptInterface

OptBase Application Class

OptInterface Class Methods

Click to jump to top of pageClick to jump to parent topicShutting Down Optimization Engines

Use the GetOptEngine function to get the OptEngine object as a handle for the optimization engine that loaded an analytic instance ID.

Use the OptEngine method named ShutDown to shut down the optimization engine. This ends the optimization engine process with the current analytic instance ID. Based on application server settings, the system restarts a new, unloaded optimization engine process that can be loaded with any other analytic instance.

See Also

ShutDown

Click to jump to top of pageClick to jump to parent topicDeleting Existing Analytic Instances

To delete an existing analytic instance for an analytic type:

  1. Shut down any optimization engines that have this analytic instance currently loaded.

  2. Using Application Engine or a similar mechanism, delete the data in the optimization application tables pertaining to that analytic instance.

    Use the analytic instance ID as the key value to find and delete analytic instance rows from scenario-managed optimization application tables.

  3. Use the function DeleteOptProbInst with the analytic type and analytic instance as arguments to delete the analytic instance ID from PeopleTools metadata.

    Note. If you try to delete an existing analytic instance that is loaded in a running optimization engine, DeleteOptProbInst returns %OptEng_Fail, and the optional status reference parameter is set to %OptEng_Exists.

See Also

DeleteOptProbInst

Click to jump to top of pageClick to jump to parent topicProgramming for Database Updates

You must plan for uncommitted database changes in your optimization PeopleCode. The PeopleSoft Optimization Framework detects pending database updates, and generates a failure status if data is not committed to the database before certain optimization methods are called.

This checking for database updates happens in runtime for the CreateOptEngine function and the following methods: RunSync, RunAsync, Shutdown, GetTraceLevel, and SetTraceLevel. Ensure that your PeopleCode performs proper database updates and commits before you execute these methods. If you use the optional parameter for detailed status that is available for these functions, or the DetailedStatus property that is available for the methods, you can check for the status of %OptEng_DB_Updates_Pending to see if there is a pending database update.

Note. The pending database update may have happened considerably earlier in the code. Forcing a commit within your PeopleCode to avoid this problem prevents roll-back on database error. Forcing a commit should be used with care.

The InsertOptProbInst and DeleteOptProbInst functions can be called only inside FieldChange, PreSaveChange and PostSaveChange PeopleCode events, and in Workflow.

This database update checking happens in compile time for the following functions: InsertOptProbInst and DeleteOptProbInst. Make sure that there are no pending database updates before you execute these methods.

Click to jump to parent topicUsing Lights-Out Mode with Optimization

This section provides an overview of lights-out mode, and discusses how to:

Click to jump to top of pageClick to jump to parent topicUnderstanding Lights-out Mode

Some optimization applications can take several hours to run. These are typically run as overnight batch jobs every night when the work load is small to regenerate the optimization solution and have it ready for end users to use in the morning hence the term lights-out mode.

In the current release, application messages communicate between the Application Engine batch job and the online optimization engine. After the Application Engine job completes and the optimization solution has been written to the database, an application message initiates the download of the data from the database batch job to the online optimization engine.

Lights-out mode uses an Application Engine PeopleCode program within PeopleSoft Process Scheduler to send requests to an application server and receive responses from it. Within the application server, the OnRequest PeopleCode runs an optimization engine process.

This diagram illustrates the lights-out process:

Lights-out process

This request and response is in the form of a rowset as shown by the example supplied with optimization, the OPT_CALL message. Also supplied as an example is an Application Engine message publish PeopleCode program called PT_OPTCALL.

Important! Application Engine includes an action of type Log Message. which PeopleSoft Process Scheduler uses to record its activity in the PS_MESSAGE_LOG table. The PeopleCode MessageBox and WinMessage built-in functions also record their activity in the PS_MESSAGE_LOG table.

During lights-out optimization, these processes can conflict with each other or with the optimization engine when one process locks a row of the table, and another process tries to access the same row.

To prevent this conflict, pay close attention to where the MessageBox or WinMessage built-in functions are used in your Application Engine PeopleCode. In general, there can't be any outstanding database updates pending when communicating with the optimization engine using application messages.

The OPT_CALL Message

The OPT_CALL message is an example of what the lights-out process uses as the message for optimization. The OPT_CALL message has a structure using a record, PT_OPTPARMS, having the fields PARMKEY and VALUE which represent a name/value pair. These send requests and responses from the Application Engine PeopleCode in PeopleSoft Process Scheduler to and from the message OnRequest PeopleCode in the application server.

The OPT_CALL message also uses a record, PT_OPTDETMSGS, which contains the information needed for processing a detailed message.

This is an example of the Message Definition page (select PeopleTools, Integration Broker, Integration Setup, Messages) showing the OPT_CALL message definition:

The OPT_CALL message is associated with the OPT_CALL service operation. The OPT_CALL service operation defines the OPT_CALL application package as a handler. This application package implements the Integration Broker methods needed to handle any messaging PeopleCode.

Click to jump to top of pageClick to jump to parent topicCreating a Request Message

This section provides an overview of the request message and describes how to create messages that:

Understanding the Request Message

For optimization, the Application Engine PeopleCode in PeopleSoft Process Scheduler sends a request OPT_CALL message. The message uses rowsets built from PT_OPTPARMS records as the request. You can use the following rowset structures as an example of how to perform certain optimization actions, by sending them as requests from the application engine program in the process scheduler to the message notification PeopleCode in the application server.

Creating an Optimization Engine

To create an optimization engine, structure the rowset as follows, using the PT_OPTPARMS record. You set key values using the PARMKEY field, and then set a value for that key field in the VALUE field.

PARMKEY Field

VALUE Field

OPTCMD

CREATE

Causes the PeopleCode program implementing the Integration Broker OnRequest method to load an optimization engine. The OPT_CALL example executes the CreateOptEngine function.

PROBINST

The name of the analytic instance.

PROCINSTANCE

The name of the process instance for this process scheduler job.

SYNCH

Y if this optimization engine load is to occur synchronously, N if asynchronously.

Checking Optimization Engine Status

To check optimization engine status (for example, to see when it finishes loading), structure the rowset as follows, using the PT_OPTPARMS record.

PARMKEY Field

VALUE Field

OPTCMD

CHECK_STATUS

Causes the PeopleCode program implementing the Integration Broker OnRequest method to check the status of an optimization engine. The OPT_CALL example executes the CheckOptEngineStatus function.

PROBINST

The name of the analytic instance.

PROCINSTANCE

The name of the process instance for this process scheduler job.

Running a Transaction

To run a transaction, structure the rowset as follows, using the PT_OPTPARMS record.

PARMKEY Field

VALUE Field

OPTCMD

RUN

Causes the PeopleCode program implementing the Integration Broker OnRequest method to run an optimization transaction. The OPT_CALL example executes the GetOptEngine method and either the RunSynch or RunAsynch method.

PROBINST

The name of the analytic instance.

PROCINSTANCE

The name of the process instance for this process scheduler job.

SYNCH

Y for a synchronous transaction, N for asynchronous.

TRANSACTION

The name of the transaction to run.

The names of one or more transaction parameters.

The value of each named transaction parameter.

Setting the Trace Level

To set a trace level, structure the rowset as follows, using the PT_OPTPARMS record.

PARMKEY Field

VALUE Field

OPTCMD

SET_TRACE_LEVEL

Causes the PeopleCode program implementing the OnRequest Integration Broker method to set the severity level at which events will be logged for an optimization engine. The OPT_CALL example executes the SetTraceLevel method.

PROBINST

The name of the analytic instance.

PROCINSTANCE

The name of the process instance for this process scheduler job.

COMPONENT

One of the following values:

  • %Opt_Engine server activity of the running optimization engine.

  • %Opt_Utility low level elements that support the running optimization engine.

  • %Opt_Datacache the in-memory database cache.

  • %Opt_Plugin the plugin being used for the running optimization engine.

SEVERITY_LEVEL

The severity level to log.

The following list starts with the most severe level; the level you specify includes all higher levels. For example, if you specify %Severity_Error, it logs %Severity_Fatal, %Severity_Status, and %Severity_Error messages and filters out the others.

  • %Severity_Fatal

  • %Severity_Status

  • %Severity_Error

  • %Severity_Warn

  • %Severity_Info

  • %Severity_Trace1

  • %Severity_Trace2

Getting the Trace Level

To get a trace level, structure the rowset as follows, using the PT_OPTPARMS record.

PARMKEY Field

VALUE Field

OPTCMD

GET_TRACE_LEVEL

Causes the PeopleCode program implementing the OnRequest Integration Broker method to get the severity level at which events will be logged for an optimization engine. The OPT_CALL example executes the GetTraceLevel method.

PROBINST

Set to the name of the analytic instance.

PROCINSTANCE

Set to the name of the process instance for this process scheduler job.

COMPONENT

One of the following values:

  • %Opt_Engine server activity of the running optimization engine.

  • %Opt_Utility low level elements that support the running optimization engine.

  • %Opt_Datacache the in-memory database cache.

  • %Opt_Plugin the plugin being used for the current opt engine.

Shutting Down an Optimization Engine

To shut down an optimization engine, structure the rowset as follows, using the PT_OPTPARMS record.

PARMKEY Field

VALUE Field

OPTCMD

SHUTDOWN

Causes the PeopleCode program implementing the OnRequest Integration Broker method to shut down an optimization engine. The OPT_CALL example executes the Shutdown method.

PROBINST

The name of the analytic instance.

PROCINSTANCE

The name of the process instance for this process scheduler job.

Click to jump to top of pageClick to jump to parent topicCreating a Response Message

This section provides an overview of the response message and describes how to create messages that:

Understanding the Response Message

For optimization, the message PeopleCode in application server receives the request messages, performs an optimization actions, and sends response OPT_CALL messages. One message uses rowsets built from PT_OPTPARMS records, the other uses rowsets from PT_DETMSGS records. You can use the rowset structures in the next section (Sending Optimization Status) as an example of how to send responses from the message notification PeopleCode in the application server to the application engine program in the process scheduler.

Sending Optimization Status

To send the status of the optimization functions and methods called within the PeopleCode program implementing the OnRequest Integration Broker method, structure the rowset as follows using the PT_OPTPARMS record. The optimization functions and messages are called in response to the request input message. You set key values using the PARMKEY field, and then set a value for that key field in the VALUE field.

PARMKEY Field

VALUE Field

STATUS

The return status of the optimization function or method that is called in the message PeopleCode.

DETAILED_STATUS

The optional detailed status returned by many of the optimization functions and methods.

Sending a Detailed Message

To send a detailed message, structure the rowset as follows, using the PT_DETMSGS record. You set key values using the PARMKEY field, and then set a value for that key field in the VALUE field.

PARMKEY Field

VALUE Field

MSGSET

The message set number. In the case of optimization, the message set number is 148.

MSGNUM

The name of the detailed message.

PARMCOUNT

The number of message parameters for the detailed message. There can be up to five parameters.

MSGPARM1

The first parameter value.

MSGPARM2

The second parameter value.

MSGPARM3

The third parameter value.

MSGPARM4

The fourth parameter value.

MSGPARM5

The fifth parameter value.

Click to jump to top of pageClick to jump to parent topicEditing the Request PeopleCode

The PT_OPTCALL Application Engine program serves as a template. It is delivered with all the sections marked as inactive. You can edit the program to suit your needs, then mark the appropriate sections active before running it. You can also use the program as a guide to creating your own Application Engine program.

The program uses these steps to send request messages to perform the following tasks:

  1. Load the optimization engine.

  2. Wait for the optimization engine load to finish.

  3. Run an optimization transaction against the loaded optimization engine.

  4. Wait for the optimization transaction to finish running.

  5. Set the trace level.

  6. Get the trace level.

  7. Shut down the optimization engine.

You can edit steps 1 and 3 to run an optimization transaction. You can also use the entire program as a template to create your own Application Engine program.

Loading an Optimization Engine

In step 1, enter the name of your analytic instance. In this example, the name of the analytic instance is FEMALE1.

If you have multiple domains, enter the local node name and the machine name and port number for your application server. In this case, the local node name is %LocalNode and the machine name and port number are foo111111:9000.

Local Message &MSG; Local Message &response; Component string &probid; Component string &isSync; Component string &procinst; Local integer &nInst; Local string &url; Local Rowset &rs; Local Row &row; Local Record &rec; Local string &stName; Local integer &stVal; &MSG = CreateMessage(OPERATION.OPT_CALL); &rs = &MSG.GetRowset(); &row = &rs.GetRow(1); &rec = &row.GetRecord(Record.PT_OPTPARMS); &rec.PARMKEY.Value = "OPTCMD"; &rec.VALUE.Value = "CREATE"; &rs.InsertRow(1); &rec = &rs.GetRow(2).PT_OPTPARMS; &rec.PARMKEY.Value = "PROBINST"; &rec.VALUE.Value = "FEMALE1"; &probid = "FEMALE1"; &rs.InsertRow(2); &rec = &rs.GetRow(3).PT_OPTPARMS; &rec.PARMKEY.Value = "PROCINSTANCE"; &nInst = Record.PT_OPT_AET.PROCESS_INSTANCE.Value; &rec.VALUE.Value = String(&nInst); &procinst = String(&nInst); &rs.InsertRow(3); &rec = &rs.GetRow(4).PT_OPTPARMS; &rec.PARMKEY.Value = "SYNCH"; &rec.VALUE.Value = "N"; &isSync = "N"; /* Specify the Application Server domain URL (foo111111:9000 in this example) */ &response = %IntBroker.SyncRequest(%LocalNode, "//foo111111:9000 e"); If &response.ResponseStatus = 0 Then &stName = &response.GetRowset().GetRow(1).GetRecord(Record.PT_OPTPARMS).Get Field(Field.PARMKEY).Value; &stVal = Value(&response.GetRowset().GetRow(1).GetRecord(Record.PT_ OPTPARMS).GetField(Field.VALUE).Value); If &stName = "STATUS" And &stVal = %OptEng_Fail Then /* Check detailed message here */ throw CreateException(148, 2, "Can not send to OptEngine"); End-If; End-If;

Running An Optimization Transaction

In step 3, enter the name of your optimization transaction and its parameter name/value pairs. In this example, the transaction name is TEST_LONG_TRANS, the first parameter name/value pair is Delay_in_Secs and 30, and the second parameter name/value pair is Sleep0_Work1 and 0.

The parameter values are stored as strings. You may need to convert them in the OnRequest PeopleCode.

Local Message &MSG; Local Message &response; Local Rowset &rs, &respRS; Local Row &row; Local Record &rec, &msgRec; Component string &probid; Component string &procinst; Component string &isSync; Local string &url = ""; Local integer &parmCount, &msgSet, &msgNum; &MSG = CreateMessage(OPERATION.OPT_CALL); &rs = &MSG.GetRowset(); &row = &rs.GetRow(1); &rec = &row.GetRecord(Record.PT_OPTPARMS); &rec.PARMKEY.Value = "OPTCMD"; &rec.VALUE.Value = "RUN"; &rs.InsertRow(1); &rec = &rs.GetRow(2).PT_OPTPARMS; &rec.PARMKEY.Value = "PROBINST"; &rec.VALUE.Value = &probid; &rs.InsertRow(2); &rec = &rs.GetRow(3).PT_OPTPARMS; &rec.PARMKEY.Value = "PROCINSTANCE"; &rec.VALUE.Value = &procinst; &rs.InsertRow(3); &rec = &rs.GetRow(4).PT_OPTPARMS; &rec.PARMKEY.Value = "SYNCH"; &rec.VALUE.Value = &isSync; &rs.InsertRow(4); &rec = &rs.GetRow(5).PT_OPTPARMS; &rec.PARMKEY.Value = "TRANSACTION"; &rec.VALUE.Value = "TEST_LONG_TRANS"; &rs.InsertRow(5); &rec = &rs.GetRow(6).PT_OPTPARMS; &rec.PARMKEY.Value = "Delay_in_Secs"; &rec.VALUE.Value = "30"; &rs.InsertRow(6); &rec = &rs.GetRow(7).PT_OPTPARMS; &rec.PARMKEY.Value = "Sleep0_Work1"; &rec.VALUE.Value = "0"; /* SyncRequest will carry a url */ SQLExec("select URL from PSOPTSTATUS where PROBINST=:1 AND URL NOT LIKE '%:0';", &probid, &url); If &url = "" Then throw CreateException(148, 2, "Can not send to OptEngine"); End-If; /* Specify the Application Server domain URL. (This was specified in Step 1 in this example.) */ &response = %IntBroker.SyncRequest(%LocalNode, &url); If &response.ResponseStatus = 0 Then &stName = &response.GetRowset().GetRow(1).GetRecord(Record.PT_OPTPARMS).Get Field(Field.PARMKEY).Value; &stVal = Value(&response.GetRowset().GetRow(1).GetRecord(Record.PT_ OPTPARMS).GetField(Field.VALUE).Value); If &stName = "STATUS" And &stVal = %OptEng_Fail Then throw CreateException(148, 2, "Can not send to OptEngine"); End-If; /* Check Detailed msg here */ If &isSync = "Y" And &stVal = %OptEng_Success Then &respRS = &response.GetRowset(); &rowNum = &respRS.ActiveRowCount; For &iloop = 1 To &rowNum &msgRec = &respRS.GetRow(&iloop).GetRecord(Record.PT_OPTDETMSGS); If (&msgRec.GetField(Field.MSGSET).Value <> 0) Then &msgSet = Value(&msgRec.GetField(Field.MSGSET).Value); &msgNum = Value(&msgRec.GetField(Field.MSGNUM).Value); &parm1 = &msgRec.GetField(Field.MSGPARM1).Value; &parm2 = &msgRec.GetField(Field.MSGPARM2).Value; &parm3 = &msgRec.GetField(Field.MSGPARM3).Value; &parm4 = &msgRec.GetField(Field.MSGPARM4).Value; &parm5 = &msgRec.GetField(Field.MSGPARM5).Value; &string = MsgGetText(&msgSet, &msgNum, "Message Not Found", &parm1, &parm2, &parm3, &parm4, &parm5); End-If; End-For; End-If; End-If;

Click to jump to top of pageClick to jump to parent topicEditing the Response PeopleCode

The OPT_CALL message definition serves as a template. It is delivered to work with the PT_OPTCALL Application Engine program. You can edit the program to suit your needs, or use it as a guide when creating your own response message program.

OPT_CALL Message Program

The OPT_CALL application package implements the Integration Broker method OnRequest. The PeopleCode in this method shows application messages for lights-out mode.

Depending upon the request message, the OnRequest method PeopleCode calls appropriate optimization functions and methods to perform these tasks, and sends a response message containing the returned status and detailed messages from the optimization functions and methods.

You can use the OnRequest method PeopleCode as a template to create your own response message PeopleCode program. For example, you can edit it to run an optimization transaction, which is shown below as an example. This example is edited to match the examples for step 1 and step 3 in the PT_OPTCALL program.

Processing the Transaction Parameters

Edit the OPT_CALL application program OnRequest method to enter the name of your optimization transaction and the name/value pairs for its parameters. In this example, the transaction name is TEST_LONG_TRANS, the first parameter name/value pair is &delayParm and &delay (maps to Delay_in_Secs from the request message), and the second parameter name/value pair is &sleepParm and &isSleep (maps to Sleep0_Work1 from the request message).

The parameter values are stored as strings in step 3 of the Application Engine program. You may need to convert them here to your desired format. Here is a section of the application program showing the places to edit.

If &trans = "TEST_LONG_TRANS" Then &REC = &rs.GetRow(6).PT_OPTPARMS; ​&delayParm = &REC.PARMKEY.Value; ​&delay = Value(&REC.VALUE.Value); &REC = &rs.GetRow(7).PT_OPTPARMS; ​&sleepParm = &REC.PARMKEY.Value; ​&isSleep = Value(&REC.VALUE.Value); &myopt = GetOptEngine(&inst, &detStatus); If (&myopt = Null) Then &optstatus = %OptEng_Fail; End-If; If &myopt <> Null And &isSync = "Y" Then &optstatus = &myopt.RunSynch(&trans, ​&delayParm,&delay,&sleepParm, ​&isSleep ); &detStatus = &myopt.DetailedStatus; End-If; If &myopt <> Null And &isSync = "N" Then &myopt.ProcessInstance = &procInst; &optstatus = &myopt.RunASynch(&trans, ​&delayParm,&delay,&sleepParm, ​&is Sleep); &detStatus = &myopt.DetailedStatus; End-If; /* iif myopt=null */ End-If;

Building a Status Response Message

This section shows the a response message to send a status message for the OPT_CALL message in the application server.

/* Insert detailed status and detailed msgs into Response msg rowset */ &respRS = &response.GetRowset(); &respRS.GetRow(1).GetRecord(Record.PT_OPTPARMS).GetField(Field.PARMKEY).Value = "STATUS"; &respRS.GetRow(1).GetRecord(Record.PT_OPTPARMS).GetField(Field.VALUE).Value = String(&optstatus); &respRS.InsertRow(1); &respRS.GetRow(2).GetRecord(Record.PT_OPTPARMS).GetField(Field.PARMKEY).Value = "DETAILED_STATUS"; &respRS.GetRow(2).GetRecord(Record.PT_OPTPARMS).GetField(Field.VALUE).Value = String(&detStatus);

Building a Detailed Response Message

This section shows a response message to send a detailed message for the OPT_CALL message on the application server.

/*Either optcmd or inst is not passed in correctly, or optengine is not loaded /created correctly */ If &myopt = Null Then &msgRec = &respRS.GetRow(1).GetRecord(Record.PT_OPTDETMSGS); If &isParmBad = True Then &msgRec.GetField(Field.MSGSET).Value = 148; &msgRec.GetField(Field.MSGNUM).Value = 505; End-If; End-If; /* If it is sync transaction, insert DetailMsg to response msg */ If &myopt <> Null And &isSync = "Y" And &optcmd = "RUN" And &optstatus = %OptEng_Success Then &arrArray = &myopt.DetailMsgs; For &iloop = 1 To &arrArray.Len /* First two rows have been inserted because of PT_OPTPARMS for two status codes */ If &iloop > 2 Then &respRS.InsertRow(&iloop - 1); End-If; &msgRec = &respRS.GetRow(&iloop).GetRecord(Record.PT_OPTDETMSGS); &msgRec.GetField(Field.MSGSET).Value = String(&arrArray [&iloop][1]); &msgRec.GetField(Field.MSGNUM).Value = String(&arrArray [&iloop][2]); &msgRec.GetField(Field.PARMCOUNT).Value = String(&arrArray [&iloop][3]); &msgRec.GetField(Field.MSGPARM1).Value = String(&arrArray [&iloop][4]); &msgRec.GetField(Field.MSGPARM2).Value = String(&arrArray [&iloop][5]); &msgRec.GetField(Field.MSGPARM3).Value = String(&arrArray [&iloop][6]); &msgRec.GetField(Field.MSGPARM4).Value = String(&arrArray [&iloop][7]); &msgRec.GetField(Field.MSGPARM5).Value = String(&arrArray [&iloop][8]); End-For; End-If;

Click to jump to parent topicOptimization Built-in Functions

This section discusses the optimization functions. The functions are discussed in alphabetical order.

Click to jump to top of pageClick to jump to parent topicCreateOptEngine

Syntax

CreateOptEngine(analytic_inst, {%Synch | %ASynch}[, &detailedstatus] [, processinstance])

Description

The CreateOptEngine function instantiates an OptEngine object, loads an optimization engine with an analytic instance and returns a reference to it.

Parameters

Analytic_inst

Specify the analytic instance ID, which is a unique ID for this analytic instance in this optimization engine. This is supplied by users when they request that an optimization be run.

%Synch | %Asynch

Specify whether the optimization engine is synchronous or asynchronous. The values are:

  • %Synch: run the optimization engine synchronously.

  • %Asynch: run the optimization engine asynchronously.

&detailedstatus

Specify a variable that the engine uses to give further information about the evaluation of this function. The value returned is one of the following:

  • %OptEng_Success: The function completed successfully.

  • %OptEng_Fail: The function failed.

  • %OptEng_Invalid_Aiid: The analytic instance ID passed to the function is invalid.

  • %OptEng_Exists: An optimization engine instance already exists and is loaded.

  • %OptEng_Method_Disabled: A method is disabled or not valid.

  • %OptEng_DB_Updates_Pending: indicates that database updates are pending.

processinstance

Enter the process instance ID. You use this parameter only with lights-out processing, most likely with the subscription PeopleCode for application message.

Note. This optional parameter is positional. If you use it, you must also use the &detailedstatus parameter.

The state record that you use with Application Engine contains the process instance ID.

See Using Lights-Out Mode with Optimization.

See Using State Records.

Returns

If successful, CreateOptEngine returns an OptEngine PeopleCode object. If the function fails, it returns a null value. Examine the optional status reference parameter in case of a Null return for additional information regarding the failure.

Example

An OptEngine object variable can be scoped as Local, Component, or Global.

You declare OptEngine objects as type OptEngine. For example:

Local OptEngine &MyOptEngine; Component OptEngine &MyOpt; Global OptEngine &MyOptEng;

The following example loads an optimization engine with the analytic instance:

Local OptEngine &myopt; Local string &probinst; Local string &transaction; Local integer &detailedstatus; &probinst = GetRecord(Record.PSOPTPRBINST).GetField(Field.PROBINST).Value; &myopt = CreateOptEngine(&probinst, %Synch);

The following example shows the use of the optional status parameter:

&myopt = CreateOptEngine(&probinst, %Synch, &detailedstatus); if &myopt = Null then if &detailedstatus = %OptEng_Invalid_Piid then /*perform some action */ end_if; end_if;

Click to jump to top of pageClick to jump to parent topicCreateOptInterface

Syntax

CreateOptInterface()

Description

The CreateOptInterface function instantiates an OptInterface object.

Note. You can use this function and the OptInterface methods only within an application class that you extend from the OptBase application class, or within PeopleCode that you call from that application class. This ensures that the OptInterface PeopleCode runs only on the optimization engine.

Parameters

None.

Returns

If successful, CreateOptInterface returns an OptInterface PeopleCode object. If the function fails, it returns a null value.

Example

You declare OptInterface objects as type OptInterface. For example:

Local OptInterface &MyOptInterface; Component OptInterface &MyOptInt; Global OptInterface &MyOptInt;

The following example instantiates an OptInterface object:

Local OptInterface &myInterface; Int &status; &myInterface = CreateOptInterface(&addtionalStatus); if (&myInterface != NULL) then &status = &myInterface.ActivateModel("RMO_TEST"); if (&status = %OptInter_Fail) then /* examine &myInterface.DetailedStatus for reason */ ... end-if; else /* CreateOptInterface has returned NULL */ /* take some corrective action here */ ... end_if;

Click to jump to top of pageClick to jump to parent topicDeleteOptProbInst

Syntax

DeleteOptProbInst(probinst[, &detailedstatus])

Description

The DeleteOptProbInst function deletes the analytic instance ID from PeopleTools metadata. This function can be called only inside FieldChange, PreSaveChange and PostSaveChange PeopleCode events, and in Workflow.

Note. Use this function to delete the analytic instance ID after deleting data in optimization application tables for this analytic instance.

Parameters

probinst

Enter the analytic instance ID to delete.

&detailedstatus

(Optional) This status reference parameter returns an integer value giving further information about the evaluation of this function. The value returned is one of the following:

  • %OptEng_Success: The function completed successfully.

  • %OptEng_Fail: The function failed.

  • %OptEng_Invalid_Piid: The analytic instance ID passed to the function is invalid.

  • %OptEng_Sql_Exception: A SQLerror is encountered when access database.

  • %OptEng_Exists: An analytic server loaded with this analytic instance still exists.

Returns

Returns %OptEng_Success if successful; otherwise returns %OptEng_Fail.

Example

The following example deletes the instance for an analytic type:

Note. Whenever you add records to an analytic type, you must call DeleteOptProbInst to delete the old analytic type instances and then call InsertOptProbInst to recreate them.

Local string &probinst; Local string &probtype; Local integer &ret; &probinst = "PATSMITH"; &probtype = "QEOPT"; &ret = ​DeleteOptProbInst(&probinst, &probtype); If &ret <> %OptEng_Success Then QEOPT_WRK.MESSAGE_TEXT = "Delete of analytic instance " | &probinst | " failed."; Else QEOPT_WRK.MESSAGE_TEXT = "Analytic Instance " | &probinst | " deleted."; End-If;

The following example shows the use of the optional status parameter:

Local integer &detailedstatus; &ret = DeleteOptProbInst(&probinst, &probtype, &detailedstatus); If &ret <> %OptEng_Success AND &detailedstatus=%OptEng_Invalid_Piid then QEOPT_WRK.MESSAGE_TEXT = "Delete of analytic instance " | &probinst | " failed for bad piid."; Else QEOPT_WRK.MESSAGE_TEXT = "Analytic Instance " | &probinst | deleted."; End-If;

Click to jump to top of pageClick to jump to parent topicGetOptEngine

Syntax

GetOptEngine(probinst[,&detailedstatus])

Description

The GetOptEngine function returns a handle to an optimization engine that is already loaded with the analytic instance.

Note. You cannot call GetOptEngine from a domain other than the application server.

Parameters

probinst

Enter the analytic instance ID, which is unique ID for this analytic instance in this optimization engine.

&detailedstatus

(Optional) This status reference parameter returns an integer value giving further information about the evaluation of this function. The value returned is one of the following:

  • %OptEng_Success: The function completed successfully.

  • %OptEng_Fail: The function failed.

  • %OptEng_Invalid_Piid: The analytic instance ID passed to the function is invalid.

Returns

Returns an OptEngine PeopleCode object if successful, a null value otherwise.

Example

The following example causes an optimization engine to shut down its analytic instance:

Global string &probinst; Local OptEngine &myopt; Local integer &status; &myopt = GetOptEngine(&probinst); If &myopt <> NULL then &status = &myopt.ShutDown(); QEOPT_WRK.MESSAGE_TEXT = "Analytic Instance ID " | &probinst | " has been shutdown successfully."; End-if;

Or, you can use the optional status parameter:

&myopt = GetOptEngine(&probinst, &detailedstatus); if &myopt=NULL and &detailedstatus=%OptEng_Invalid_Piid then /* perform some action */ End-if;

Click to jump to top of pageClick to jump to parent topicGetOptProbInstList

Syntax

GetOptProbInstList(ProblemType , OutputErrorCode [, Prefix] [, &detailedstatus])

Description

The GetOptProbInstList function gets the list of all analytic instance IDs in an analytic type.

Parameters

ProblemType

Enter the name of the analytic type that you created in Application Designer.

OutputErrorCode

Future use. Always returns zero.

Prefix

(Optional) Enter a string. If used, this prefix causes the returned list to include only the analytic instance IDs that start with this prefix. If not used, all the analytic instance IDs in the analytic type are returned.

&detailedstatus

(Optional) This status reference parameter returns an integer value giving further information about the evaluation of this function. The value returned is one of the following:

  • %OptEng_Success: The function completed successfully.

  • %OptEng_Fail: The function failed.

  • %OptEng_Invalid_Piid: The analytic type name passed to the function is invalid.

Returns

Returns an array of strings containing the optimization analytic instance list.

Example

The following example shows the usage of GetOptProbInstList to fill the display field on a page:

Global string &probinst; Local integer &detailedstatus; Local integer &iloop; Local array of string &instarray; QEOPT.OPERATOR = %UserId; &instarray = GetOptProbInstList(QEOPT.PROBTYPE, &ret, &detailedstatus); If &ret <> %OptEng_Success Then QEOPT_WRK.MESSAGE_TEXT = "Could not get analytic instances for analytic type " | QEOPT.PROBTYPE ; Else For &iloop = 1 To &instarray.Len QEOPT_WRK.MESSAGE_TEXT = QEOPT_WRK.MESSAGE_TEXT | &instarray[&iloop] | " "; End-For; End-If;

The following example shows the use of the optional status parameter:

&instarray = GetOptProbInstList(QEOPT.PROBTYPE, &ret, &detailedstatus); If &ret <> %OptEng_Success and &detailedstatus=%OptEng_Invalid_Piid Then QEOPT_WRK.MESSAGE_TEXT = "Could not get analytic instances for analytic type " | QEOPT.PROBTYPE | "because bad piid" ; End-If;

Click to jump to top of pageClick to jump to parent topicInsertOptProbInst

Syntax

InsertOptProbInst(probinst, ProblemType[, &detailedstatus] [,Description])

Description

The InsertOptProbInst function inserts a new analytic instance ID into the PeopleTools metadata.

The InsertOptProbInst function can be called only inside FieldChange, PreSave and PostSave PeopleCode events, and in Workflow.

Note. You must use this function to create the analytic instance ID before inserting data into optimization application tables for this analytic instance.

Parameters

probinst

Enter the analytic instance ID to be inserted into the analytic type.

ProblemType

Enter the name of the analytic type that you created in Application Designer.

&detailedstatus

(Optional) This status reference parameter returns an integer value giving further information about the evaluation of this function. The value returned is one of the following:

  • %OptEng_Success: The function completed successfully.

  • %OptEng_Fail: The function failed.

  • %OptEng_Invalid_Piid: The analytic instance ID passed to the function is invalid.

Description

(Optional) Specify a description for the analytic instance. This parameter takes a string value.

Returns

This method returns a constant. Valid values are:

Value

Description

%OptEng_Success

Returned if method succeeds.

%OptEng_Fail

Returned if the method fails.

Example

Local string &probinst; Local string &probtype; Local integer &ret; Local integer &detailedstatus; &probinst = "PATSMITH"; &probtype = "QEOPT"; &probDescr = "New QEOPT instance"; &ret = InsertOptProbInst(&probinst, &probtype, &probDescr); If &ret <> %OptEng_Success Then QEOPT_WRK.MESSAGE_TEXT = "Insert of analytic instance " | &probinst | " failed."; Else QEOPT_WRK.MESSAGE_TEXT = "Analytic Instance " | &probinst | " created."; End-If;

The following example shows the use of the optional status parameter:

&ret = InsertOptProbInst(&probinst, &probtype, &detailedstatus); If &ret <> %OptEng_Success and &detailedstatus=%OptEng_Invalid_Piid Then QEOPT_WRK.MESSAGE_TEXT = "Insert of analytic instance " | &probinst | " failed for bad piid."; End-if;

Click to jump to top of pageClick to jump to parent topicIsValidOptProbInst

Syntax

IsValidOptProbInst(probinst [, &detailedstatus])

Description

IsValidOptProbInst determines if a given analytic instance exists in the optimization metadata.

Parameters

probinst

Enter the analytic instance ID to be validated.

&detailedstatus

(Optional) This status reference parameter returns an integer value giving further information about the evaluation of this function. The value returned is one of the following:

  • %OptEng_Success: The function completed successfully.

  • %OptEng_Invalid_Piid: The analytic type name passed to the function is invalid.

Returns

This method returns a constant. Valid values are:

Value

Description

%OptEng_Success

Returned if method succeeds.

%OptEng_Fail

Returned if the method fails.

Example

Local string &probinst; Local integer &detailedstatus; Local integer &ret; &probinst = "PATSMITH"; &ret = IsValidOptProbInst(&probinst, &detailedstatus); If &ret <> %OptEng_Success and &detailedstatus=%OptEng_Invalid_Piid Then <perform some action> End-if;

Click to jump to parent topicOptEngine Class Methods

This section discusses the optimization methods for the OptEngine PeopleCode class. The methods are listed in alphabetical order.

Click to jump to top of pageClick to jump to parent topicCheckOptEngineStatus

Syntax

CheckOptEngineStatus()

Description

The CheckOptEngineStatus method returns the status of the optimization engine, using a combination of its return value and the DetailedStatus OptEngine class property. Keep the following in mind:

For example, CheckOptEngineStatus can return %OptEng_Idle and DetailedStatus is %OptEng_Success. For CheckOptEngineStatus, DetailedStatus can have the value:

Note. Before this method is called, the CreateOptEngine or GetOptEngine must be called.

Returns

Returns an integer for the status of the optimization engine. These numbers are message IDs belonging to message set 148 in the message catalog.

Numeric Value

Constant Value

Description

21

%OptEng_Not_Loaded

The optimization engine process is running, but is not currently loaded with an application problem.

22

%OptEng_Busy_Loading

The optimization engine is busy loading an application problem. It will not accept transaction requests until loading completes.

23

%OptEng_Idle

The optimization engine is loaded with an application problem and waiting for a transaction request.

24

%OptEng_Busy

The optimization engine is busy processing a transaction request for the loaded application problem. It will not accept additional transaction requests until the current one completes.

26

%OptEng_Unknown

An error has occurred. The optimization engine status cannot be determined.

Example

This PeopleCode example shows optimization engine status being checked:

Local OptEngine &myopt; Local string &probinst; Local integer &status; &myopt = GetOptEngine("PATSMITH"); /* Initialize the DESCRLONG field in the QE_FUNCLIB_OPT record to null. */ GetLevel0().GetRow(1).GetRecord(Record.QE_FUNCLIB_OPT).DESCRLONG.Value = ""; &status = &myopt.CheckOptEngineStatus(); GetLevel0().GetRow(1).GetRecord(Record.QE_FUNCLIB_OPT).DESCRLONG.Value = "Opt Engine status = " | MsgGet(148, &status, "Could not send to the OptEngine.");

You can also retrieve the detailed status:

Local integer &detailedstatus &status = &myopt.CheckOptEngineStatus(); &detailedstatus = &myopt.DetailedStatus;

Click to jump to top of pageClick to jump to parent topicFillRowset

Syntax

FillRowset(PARAM_NAME, &Rowset[, &functionstatus])

Description

This method gets the value of a transaction output parameter that is a rowset. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

When using the OptEngine DetailedStatus property, keep the following in mind:

For example, FillRowset returns %OptEng_Fail, and DetailedStatus is %OptEng_Method_Disabled.

For FillRowset, the DetailedStatus property can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

&Rowset

Enter the rowset containing the values. This rowset must be a single record rowset, and the record must match the record name associated with the transaction parameter in the analytic type definition.

&functionstatus

(Optional) This status reference parameter returns an integer value giving further information about the evaluation of this function. The value returned is one of the following:

  • OptEng_Success: The function completed successfully.

  • OptEng_Fail: The function failed.

  • OptEng_Method_Disabled: A method is disabled or not valid.

Returns

This method returns a constant. Valid values are:

Value

Description

%OptEng_Success

Returned if method succeeds.

%OptEng_Fail

Returned if the method fails.

Example

The following PeopleCode example runs a synchronous optimization transaction named RETURN_MACHINE_UNAVAILABLE. It has these parameters:

This PeopleCode example sets input parameter values and gets an output parameter value:

Local OptEngine &myopt; Local integer &status; Local string &machname; Local Rowset &rs; &myopt = GetOptEngine("PATSMITH"); &machname = QEOPT_WRK.MACHINE_NAME.Value; /* Run the RETURN_MACHINE_UNAVAILABLE transaction synchronously with input values. */ &status = &myopt.RunSynch("RETURN_MACHINE_UNAVAILABLE", "MACHINE_NAME", &machname); If Not &status Then QEOPT_WRK.MESSAGE_TEXT = " RETURN_MACHINE_UNAVAILABLE transaction failed."; Return; End-If; /* Get output value from the RETURN_MACHINE_UNAVAILABLE transaction. */ &rs = CreateRowset(Record.MACHINE_WRK); &status = &myopt.FillRowset("RETURN_TIMES", &rs);

You can also use the [new->] DetailedStatus property as follows:

&status = &myopt.FillRowset("RETURN_TIMES", &rs); if &status=%OptEng_Fail and &myopt.DetailedStatus=%OptEng_Method_Disabled then /* perform some action */ End-if;

Click to jump to top of pageClick to jump to parent topicGetDate

Syntax

GetDate(PARAM_NAME[, &status])

Description

This method gets the value of a transaction output parameter with a data type of Date. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The OptEngine DetailedStatus property indicates the completion status of the OptEngine method call GetDate. For GetDate, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns a Date object; use this method when that is the data type of the transaction output parameter value.

Example

See OptEngine class: GetNumber method.

Click to jump to top of pageClick to jump to parent topicGetDateArray

Syntax

GetDateArray(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type Array of Date. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The OptEngine DetailedStatus property indicates the completion status of the OptEngine method call GetDateArray. For GetDateArray, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns an Array of Date object; use this method when that is the data type of the transaction output parameter value.

Example

See OptEngine class: GetStringArray method.

Click to jump to top of pageClick to jump to parent topicGetDateTime

Syntax

GetDateTime(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type of DateTime. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetDateTime. For GetDateTime, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns a DateTime object; use this method when that is the data type of the transaction output parameter value.

Example

See OptEngine class: GetNumber method.

Click to jump to top of pageClick to jump to parent topicGetDateTimeArray

Syntax

GetDateTimeArray(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type Array of DateTime. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetDateTimeArray. For GetDateTimeArray, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns an Array of DateTime object; use this method when that is the data type of the transaction output parameter value.

Example

See OptEngine class: GetStringArray method.

Click to jump to top of pageClick to jump to parent topicGetNumber

Syntax

GetNumber(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type of Number. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetNumber. For GetNumber, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns a Number object; use this method when that is the data type of the transaction output parameter value.

Example

The following PeopleCode example runs a synchronous optimization transaction named IS_MACHINE_AVAILABLE. It has these parameters:

This PeopleCode example sets input parameter values and gets an output parameter value:

Local OptEngine &myopt; Local integer &status; Local string &machname; Local datetime &begindate; Local datetime &enddate; &myopt = GetOptEngine("PATSMITH"); &machname = QEOPT_WRK.MACHINE_NAME.Value; &begindate = QEOPT_WRK.BEGIN_DATE.Value; &enddate = QEOPT_WRK.END_DATE.Value; /* Run the IS_MACHINE_AVAILABLE transaction synchronously with input values. */ &status = &myopt.RunSynch("IS_MACHINE_AVAILABLE", "MACHINE_NAME", &machname, "BEGIN_DATE", &begindate, "END_DATE", &enddate); If Not &status Then QEOPT_WRK.MESSAGE_TEXT = "IS_MACHINE_AVAILABLE transaction failed."; Return; End-If; /* Get output value from the IS_MACHINE_AVAILABLE transaction. */ QEOPT_WRK.AVAILABLE_FLAG = &myopt.GetNumber("AVAILABLE_FLAG");

You can use the DetailedStatus property as follows:

QEOPT_WRK.AVAILABLE_FLAG = &myopt.GetNumber("AVAILABLE_FLAG"); if &myopt.DetailedStatus=%OptEng_Fail then /* perform some action */ End-if;

Click to jump to top of pageClick to jump to parent topicGetNumberArray

Syntax

GetNumberArray(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type Array of Number. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetNumberArray. For GetNumberArray, DetailedStatus can have the value:

Note. Do not pass an array of type Integer as a transaction parameter. Use an array of type Number instead.

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns an Array of Number object; use this method when that is the data type of the transaction output parameter value.

Example

See OptEngine class: GetStringArray method.

Click to jump to top of pageClick to jump to parent topicGetString

Syntax

GetString(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type of String. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetString. For GetString, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns a String object; use this method when that is the data type of the transaction output parameter value.

Example

See OptEngine class: GetNumber method.

Click to jump to top of pageClick to jump to parent topicGetStringArray

Syntax

GetStringArray(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type Array of String. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetStringArray. For GetStringArray, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns an Array of String object; use this method when that is the data type of the transaction output parameter value.

Example

The following PeopleCode example runs a synchronous optimization transaction named ARE_MACHINES_AVAILABLE. It has these parameters:

This PeopleCode example sets input parameter values and gets an output parameter value:

Local OptEngine &myopt; Local integer &status; Local array of string &machnames; Local datetime &begindate; Local datetime &enddate; &myopt = GetOptEngine("PATSMITH"); &begindate = QEOPT_WRK.BEGIN_DATE.Value; &enddate = QEOPT_WRK.END_DATE.Value; /* Run the ARE_MACHINES_AVAILABLE transaction synchronously with input values. */ &status = &myopt.RunSynch("ARE_MACHINES_AVAILABLE", "BEGIN_DATE", &begindate, "END_DATE", &enddate); If &status=%OptEng_Fail Then QEOPT_WRK.MESSAGE_TEXT = "ARE_MACHINES_AVAILABLE transaction failed."; Return; End-If; /* Get output value from the ARE_MACHINES_AVAILABLE transaction. */ &machnames = &myopt.GetStringArray("MACHINE_NAMES");

The following example shows the use of the DetailedStatus property:

Local array of string &machnames; &machnames = &myopt.GetStringArray("MACHINE_NAMES"); if &myopt.DetailedStatus=%OptEng_Fail then /* perform some action */ End-if;

Click to jump to top of pageClick to jump to parent topicGetTime

Syntax

GetTime(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type of Time. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetTime. For GetTime, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns a Time object; use this method when that is the data type of the transaction output parameter value.

Example

See OptEngine class: GetNumber method.

Click to jump to top of pageClick to jump to parent topicGetTimeArray

Syntax

GetTimeArray(PARAM_NAME)

Description

This method gets the value of a transaction output parameter with a data type Array of Time. This cannot be used with the RunAsynch method; RunSynch is needed to make the transaction output parameter values immediately available.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetTimeArray. For GetTimeArray, DetailedStatus can have the value:

Parameters

PARAM_NAME

Enter a string for the name of the output parameter to get from the transaction that was just performed with RunSynch. This parameter must be defined as an output or both (input and output) in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

Returns an Array of Time object; use this method when that is the data type of the transaction output parameter value.

Example

See OptEngine class: GetStringArray method.

Click to jump to top of pageClick to jump to parent topicGetTraceLevel

Syntax

GetTraceLevel(component)

Description

GetTraceLevel gets the severity level at which events are logged for a given component.

The DetailedStatus OptEngine property indicates the completion status of the OptEngine method call GetTraceLevel. For GetTraceLevel, DetailedStatus can have the value:

Parameters

component

Enter one of the following PeopleCode constants: Opt_Engine, Opt_Utility, Opt_Datacache, or Opt_Plugin.

Returns

Returns one of the following.

Example

Local OptEngine &myopt; Local integer &tracelevel; &myopt = GetOptEngine("PATSMITH"); &tracelevel = &myopt.GetTraceLevel(%Opt_Engine); if &myopt.DetailedStatus = %OptEng_Success then if (&tracelevel = %Severity_Info_ then winmessage("Severity level for the OptEngine is 'Info'"); End-if; End-if;

Click to jump to top of pageClick to jump to parent topicRunAsynch

Syntax

RunAsynch(TRANSACTION, PARM_PAIRS)

Description

The RunAsynch method requests the optimization engine to run the transaction in asynchronous mode.

When using the DetailedStatus OptEngine property, keep the following in mind:

For example, RunASynch can return %OptEng_Fail and DetailedStatus is %OptEng_DB_Updates_Pending. For RunASynch, DetailedStatus can have the value:

Parameters

TRANSACTION

Enter a string for the name of the transaction to run.

PARAM_PAIRS

Enter the name and value pairs (string name and value) for this transaction. Not used if the transaction has no parameters. Parameters are defined in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

This method returns a constant. Valid values are:

Value

Description

%OptEng_Success

Returned if method succeeds.

%OptEng_Fail

Returned if the method fails.

Example

This PeopleCode example runs an asynchronous optimization transaction named SOLVE. It has no input or output parameters. The SOLVE transaction solves the exercise scheduling problem and puts the results into the QE_RWSM_EXERSCH table.

Local OptEngine &myopt; Local integer &status; &myopt = GetOptEngine("PATSMITH"); /* Run the SOLVE transaction asynchronously with input values. */ &status = &myopt.RunAsynch("SOLVE"); If &status=%OptEng_Fail Then QEOPT_WRK.MESSAGE_TEXT = "SOLVE transaction failed."; Return; End-If;

The following example shows the use of the DetailedStatus property.

Local integer &status; &status = myopt.RunAsynch("SOLVE"); if &status=%OptEng_Fail and &myopt.DetailedStatus=%OptEng_Method_Disabled then <perform some action> End-if;

Click to jump to top of pageClick to jump to parent topicRunSynch

Syntax

RunSynch(TRANSACTION, PARM_PAIRS)

Description

The RunSynch method requests the optimization engine to run the transaction in synchronous mode.

When using the DetailedStatus OptEngine property, keep the following in mind:

For example, RunSynch can return %OptEng_Fail and DetailedStatus is %OptEng_DB_Updates_Pending. For RunSynch, DetailedStatus can have the value:

Parameters

TRANSACTION

Enter a string for the name of the transaction to run.

PARAM_PAIRS

Enter the name and value pairs (string name and value) for this transaction. Not used if the transaction has no parameters. Parameters are defined in the analytic type definition.

See Configuring Analytic Type Transactions.

Returns

This method returns a constant. Valid values are:

Value

Description

%OptEng_Success

Returned if method succeeds.

%OptEng_Fail

Returned if the method fails.

Example

The following PeopleCode example runs a synchronous optimization transaction named IS_MACHINE_AVAILABLE. It has these parameters:

This PeopleCode example sets input parameter values and gets an output parameter value:

Local OptEngine &myopt; Local integer &status; Local string &machname; Local datetime &begindate; Local datetime &enddate; &myopt = GetOptEngine("PATSMITH"); &machname = QEOPT_WRK.MACHINE_NAME.Value; &begindate = QEOPT_WRK.BEGIN_DATE.Value; &enddate = QEOPT_WRK.END_DATE.Value; /* Run the IS_MACHINE_AVAILABLE transaction synchronously with input values. */ &status = &myopt.RunSynch("IS_MACHINE_AVAILABLE", "MACHINE_NAME", &machname, "BEGIN_DATE", &begindate, "END_DATE", &enddate); If &status=%OptEng_Fail Then QEOPT_WRK.MESSAGE_TEXT = "IS_MACHINE_AVAILABLE transaction failed."; Return; End-If; /* Get output value from the IS_MACHINE_AVAILABLE transaction. */ QEOPT_WRK.AVAILABLE_FLAG = &myopt.GetNumber("AVAILABLE_FLAG");

Or, the following example shows the use of the DetailedStatus property.

Local integer &status; &status = myopt.RunSynch("SOLVE"); if &status=%OptEng_Fail and &myopt.DetailedStatus=%OptEng_Method_Disabled then <perform some action> End-if;

Click to jump to top of pageClick to jump to parent topicSetTraceLevel

Syntax

SetTraceLevel(component, severity )

Description

SetTraceLevel sets the severity level at which events are logged for a given component.

When using the DetailedStatus OptEngine property, keep the following in mind:

For example, SetTraceLevel can return %OptEng_Fail and DetailedStatus is %OptEng_DB_Updates_Pending. For SetTraceLevel, DetailedStatus can have the value:

Parameters

component

Use one of the following PeopleCode constants: Opt_Engine, Opt_Utility, Opt_Datacache, or Opt_Plugin.

severity

Use one of the following PeopleCode constants. These options set the degree to which errors are logged. You can set the tracing levels differently for various parts of your program. This enables you to control the amount of trace information that your program generates.

The following list shows the order of the severity, starting with the highest level. For example, %Severity_Error logs %Severity_Fatal, %Severity_Status, and %Severity_Error messages, while the system filters out other messages. Keep in mind that the higher the severity, the greater the performance overhead.

  • %Severity_Fatal

  • %Severity_Status

  • %Severity_Error

  • %Severity_Warn

  • %Severity_Info

  • %Severity_Trace1

  • %Severity_Trace2

Returns

This method returns a constant. Valid values are:

Value

Description

%OptEng_Success

Returned if method succeeds.

%OptEng_Fail

Returned if the method fails.

Example

Local OptEngine &myopt; Local integer &status; Local string &machname; Local datetime &begindate; Local datetime &enddate; &myopt = GetOptEngine("PATSMITH"); &status = &myopt.SetTraceLevel(%Opt_Engine, %Severity_Warn); if &status = %OptEng_Fail then <example: notify user that set trace action has failed> End-if;

Click to jump to top of pageClick to jump to parent topicShutDown

Syntax

ShutDown()

Description

The ShutDown method requests the optimization engine to shut down.

If the optimization engine cannot be contacted for shutdown, the return status is %OptEng_Fail and the DetailedStatus property is OptEng_Not_Available.

When using the DetailedStatus OptEngine property, keep the following in mind:

For example, Shutdown can return %OptEng_Fail and DetailedStatus is %OptEng_DB_Updates_Pending. For Shutdown, DetailedStatus can have the value:

Note. Before this method is called, CreateOptEngine or GetOptEngine must be called. Call ShutDown to shut down optimization engines even when running in Application Engine.

Parameters

None.

Returns

This method returns a constant. Valid values are:

Value

Description

%OptEng_Success

Returned if method succeeds.

%OptEng_Fail

Returned if the method fails.

Example

This PeopleCode example shows an optimization engine being shut down:

Local OptEngine &myopt; Local integer &status; &myopt = GetOptEngine("PATSMITH"); /* Shut down the optimization engine */ &status = &myopt.ShutDown(); If &status=%OptEng_Fail Then QEOPT_WRK.MESSAGE_TEXT = "PATSMITH optimization engine shutdown failed."; Return; Else QEOPT_WRK.MESSAGE_TEXT = "PATSMITH optimization engine shutdown successful."; Return; End-If;

The following example shows the use of the DetailedStatus property:

Local integer &status; &status = myopt.ShutDown(); if &status=%OptEng_Fail and &myopt.DetailedStatus=%OptEng_Method_Disabled then <perform some action> End-if;

Click to jump to parent topicOptEngine Class Properties

This section lists the optimization properties for the OptEngine PeopleCode class. The properties are listed in alphabetical order.

Click to jump to top of pageClick to jump to parent topicDetailMsgs

Description

The DetailMsgs property returns a list of messages generated by an optimization engine. Use DetailMsgs after you use the RunAsynch and RunSynch methods to check the status messages for an optimization transaction.

If the transaction fails, detailed messages are automatically shown to the user. If the transaction succeeds, warnings and informational messages may be generated by the transaction. Use this property to retrieve those messages and make them available to the user.

DetailMsgs provides a two-dimensional array containing the message set ID, the message number in the message catalog, and any arguments. Each row in the two-dimensional array has the following structure:

  1. Message set ID.

  2. Message number.

  3. Number of message arguments.

  4. Argument1.

  5. Argument2.

  6. Argument3.

  7. Argument4.

  8. Argument5.

A maximum of five arguments is supported for each message.

Note. To hold the property value returned, you need to declare an array of array of type Any.

Note. Before this method is called, you must call CreateOptEngine or GetOptEngine.

Example

Local OptEngine &myopt; Local integer &status; Local string &piid; Local string &string; Local array of array of any &arrArray; &NEWLINE = Char(10); &string = ""; &piid = GetRecord(Record.PSOPTPRBINST).GetField(Field.PROBINST).Value; &myopt = GetOptEngine(&piid); &status = &myopt.RunSynch("TEST_TRANSACTION"); If (&status = %OptEng_Success) then &arrArray = &myopt.DetailMsgs; For &iloop = 1 To &arrArray.Len &string = &string | &NEWLINE | MsgGetText(&arrArray [&iloop][1] /*message set* /, &arrArray [&iloop][2] /*message id*/, "Message Not Found",&arrArray[&iloop][4], &arrArray [&iloop][5],&arrArray [&iloop][6], &arrArray [&iloop][7],&arrArray[&iloop][8]); End-For; GetLevel0().GetRow(1).GetRecord(Record.QE_FUNCLIB_OPT).DESCRLONG.Value = &string; End-If;

Click to jump to top of pageClick to jump to parent topicDetailedStatus

Description

The DetailedStatus property contains the detailed execution status of an OptEngine method after the method is executed.

Example

Local integer &status; &status = myopt.ShutDown(); if &status=%OptEng_Fail and &myopt.DetailedStatus=%OptEng_Method_Disabled then <perform some action> End-if;

Click to jump to parent topicOptBase Application Class

This PeopleCode application class is part of the PT_OPT_BASE application package. It establishes the basic framework for developing PeopleCode that invokes the Optimization PeopleCode plug-in. To use the plug-in, you develop a application class that extends the OptBase application class. OptBase contains the following types of methods:

Note. The analytic type definition to which these methods apply is the one that specifies this derived application class.

The CreateOptInterface function is the only optimization built-in function that you can use within an application class that you extend from the OptBase application class, or within PeopleCode that you call from that application class.

Optbase Callback Methods

PeopleSoft Optimization Framework has a built-in callback functionality when the OptInterface PeopleCode calls an Optimization PeopleCode plug-in transaction, it first determines whether you designated one or more records in your analytic type definition as callback records. For each callback record, the framework determines if any the record's database rows have been inserted, deleted, or updated since the optimization datacache was populated. If any changes have occurred, the framework propagates those changes to the datacache before invoking the transaction.

PeopleSoft provides methods that the framework uses to apply its callback functionality. In combination with the framework's callback changes, you might want to perform additional processing for your own purposes, including updating any derived data structures that are used by your optimization application. You can accomplish this by extending the callback methods and adding your own PeopleCode. Each callback method launches under different circumstances.

Note. Don't call any of these methods in your own PeopleCode. They're called automatically at the appropriate moment by PeopleSoft Optimization Framework, which enables your added functionality to run within each method.

Following is a list of the abstract callback placeholder methods documented as part of the PT_OPT_BASE:OptBase application class:

Important! If any record in your analytic type definition is designated a callback record, you must ensure that you extend all of the callback methods in your extended class, even if each extended method contains only a Return statement. Otherwise your Optimization PeopleCode plug-in will fail.

See Configuring Analytic Type Records.

Click to jump to parent topicOptBase Class Methods

This section discusses the abstract base class placeholder methods for the PT_OPT_BASE:OptBase application class. The methods are listed in alphabetical order.

Click to jump to top of pageClick to jump to parent topicGetParmDate

Syntax

GetParmDate(parmName, &parmVal)

Description

The GetParmDate method retrieves a Date parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Date variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmDateArray

Syntax

GetParmDateArray(parmName, &parmVal)

Description

The GetParmDateArray method retrieves a Date array parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Date array variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmDateTime

Syntax

GetParmDateTime(parmName, &parmVal)

Description

The GetParmDateTime method retrieves a DateTime parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a DateTime variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmDateTimeArray

Syntax

GetParmDateTimeArray(parmName, &parmVal)

Description

The GetParmDateTimeArray method retrieves a DateTime array parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a DateTime array variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmNumber

Syntax

GetParmNumber(parmName, &parmVal)

Description

The GetParmNumber method retrieves a Number parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Number variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmNumberArray

Syntax

GetParmNumberArray(parmName, &parmVal)

Description

The GetParmNumberArray method retrieves a Number array parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Number array variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmInt

Syntax

GetParmInt(parmName, &parmVal)

Description

The GetParmInt method retrieves an Integer parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify an Integer variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmIntArray

Syntax

GetParmIntArray(parmName, &parmVal)

Description

The GetParmIntArray method retrieves a Number array parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Number array variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmString

Syntax

GetParmString(parmName, &parmVal)

Description

The GetParmString method retrieves a String parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a String variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmStringArray

Syntax

GetParmStringArray(parmName, &parmVal)

Description

The GetParmStringArray method retrieves a String array parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a String array variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmTime

Syntax

GetParmTime(parmName, &parmVal)

Description

The GetParmTime method retrieves a Time parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Time variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicGetParmTimeArray

Syntax

GetParmTimeArray(parmName, &parmVal)

Description

The GetParmTimeArray method retrieves a Time array parameter value that passed as input by any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Time array variable to contain the value passed as input by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicInit

Syntax

Init()

Description

The Init method launches when the CreateOptEngine built-in function loads an analytic instance that uses the Optimization PeopleCode plug-in.

Use this method to perform additional processing for your own purposes, including checking table data, or any functionality you want to apply before any plug-in transactions run. You accomplish this by adding your own PeopleCode to the extended method.

Don't call this method in your own PeopleCode. It's called automatically at the appropriate moment by PeopleSoft Optimization Framework, which enables your added functionality to run before any other code in your extended class.

Note. If you don't extend this method, PeopleSoft Optimization Framework calls its base version from the OptBase application class.

Parameters

None.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicOptDeleteCallback

Syntax

OptDeleteCallback(&Record)

Description

The OptDeleteCallback method launches when PeopleSoft Optimization Framework propagates to the datacache any database deletions that it encounters for a callback record.

Use this method to perform additional processing for your own purposes, including modifying any derived data structures that might be affected by the deletion. You accomplish this by adding your own PeopleCode to the extended method.

Don't call this method in your own PeopleCode. It's called automatically at the appropriate moment by PeopleSoft Optimization Framework, which enables your added functionality to run.

Important! If you designate any record in the analytic type definition as a callback record, you must ensure that you extend this callback method in your derived class, even if the extended method contains only a Return statement. Otherwise the Optimization PeopleCode plug-in will fail.

Parameters

&Record

Specifies a record variable that contains the keys of the data row to be deleted.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicOptInsertCallback

Syntax

OptInsertCallback(&Record)

Description

The OptInsertCallback method launches when PeopleSoft Optimization Framework propagates to the datacache any database insertion that it encounters for a callback record.

Use this method to perform additional processing for your own purposes, including modifying any derived data structures that might be affected by the insertion. You accomplish this by adding your own PeopleCode to the extended method.

Don't call this method in your own PeopleCode. It's called automatically at the appropriate moment by PeopleSoft Optimization Framework, which enables your added functionality to run.

Important! If you designate any record in the analytic type definition as a callback record, you must ensure that you extend this callback method in your derived class, even if the extended method contains only a Return statement. Otherwise the Optimization PeopleCode plug-in will fail.

Parameters

&Record

Specifies a record variable that contains the new data row to be inserted.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicOptPostUpdateCallback

Syntax

OptPostUpdateCallback(&OldRecord, &NewRecord)

Description

The OptPostUpdateCallback method launches after PeopleSoft Optimization Framework propagates to the datacache any database update that it encounters for a callback record.

Use this method to perform additional processing for your own purposes, including modifying any derived data structures that might have been affected by the update. You accomplish this by adding your own PeopleCode to the extended method. The parameters provide the previous and current content of the row.

Don't call this method in your own PeopleCode. It's called automatically at the appropriate moment by PeopleSoft Optimization Framework, which enables your added functionality to run.

Important! If you designate any record in the analytic type definition as a callback record, you must ensure that you extend this callback method in your derived class, even if the extended method contains only a Return statement. Otherwise the Optimization PeopleCode plug-in will fail.

Parameters

&OldRecord

Specifies a record variable that contains the pre-update content of the data row that was updated.

&NewRecord

Specifies a record variable that contains the post-update content of the data row that was updated.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicOptPreUpdateCallback

Syntax

OptPreUpdateCallback(&OldRecord, &NewRecord)

Description

The OptPreUpdateCallback method launches before PeopleSoft Optimization Framework propagates to the datacache any database update that it encounters for a callback record.

Use this method to perform additional processing for your own purposes, including modifying any derived data structures that might be affected by the update. You accomplish this by adding your own PeopleCode to the extended method. The parameters provide the current and future content of the row.

Don't call this method in your own PeopleCode. It's called automatically at the appropriate moment by PeopleSoft Optimization Framework, which enables your added functionality to run.

Important! If you designate any record in the analytic type definition as a callback record, you must ensure that you extend this callback method in your derived class, even if the extended method contains only a Return statement. Otherwise the Optimization PeopleCode plug-in will fail.

Parameters

&OldRecord

Specifies a record variable that contains the pre-update content of the data row to be updated.

&NewRecord

Specifies a record variable that contains the post-update content of the data row to be updated.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicOptRefreshCallback

Syntax

OptRefreshCallback()

Description

The OptRefreshCallback method launches after PeopleSoft Optimization Framework propagates to the datacache all database insertions, deletions, and updates that it encounters for all callback records.

Use this method to perform additional processing for your own purposes, including modifying any derived data structures that might be affected by the modifications. You accomplish this by adding your own PeopleCode to the extended method.

Don't call this method in your own PeopleCode. It's called automatically at the appropriate moment by PeopleSoft Optimization Framework, which enables your added functionality to run.

Important! If you designate any record in the analytic type definition as a callback record, you must ensure that you extend this callback method in your derived class, even if the extended method contains only a Return statement. Otherwise the Optimization PeopleCode plug-in will fail.

Parameters

None.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmDate

Syntax

SetOutputParmDate(parmName, &parmVal)

Description

Use the SetOutputParmDate method to pass a Date parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Date variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmDateArray

Syntax

SetOutputParmDateArray(parmName, &parmVal)

Description

Use the SetOutputParmDateArray method to pass a Date array parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Date array variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmDateTime

Syntax

SetOutputParmDateTime(parmName, &parmVal)

Description

Use the SetOutputParmDateTime method to pass a DateTime parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a DateTime variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmDateTimeArray

Syntax

SetOutputParmDateTimeArray(parmName, &parmVal)

Description

Use the SetOutputParmDateTimeArray method to pass a DateTime array parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a DateTime array variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmNumber

Syntax

SetOutputParmNumber(parmName, &parmVal)

Description

Use the SetOutputParmNumber method to pass a Number parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Number variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmNumberArray

Syntax

SetOutputParmNumberArray(parmName, &parmVal)

Description

Use the SetOutputParmNumberArray method to pass a Number array parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Number array variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmInt

Syntax

SetOutputParmInt(parmName, &parmVal)

Description

Use the SetOutputParmInt method to pass an Integer parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify an Integer variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmIntArray

Syntax

SetOutputParmIntArray(parmName, &parmVal)

Description

Use the SetOutputParmIntArray method to pass a Number array parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Number array variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmString

Syntax

SetOutputParmString(parmName, &parmVal)

Description

Use the SetOutputParmString method to pass a String parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a String variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmStringArray

Syntax

SetOutputParmStringArray(parmName, &parmVal)

Description

Use the SetOutputParmStringArray method to pass a String array parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a String array variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmTime

Syntax

SetOutputParmTime(parmName, &parmVal)

Description

Use the SetOutputParmTime method to pass a Time parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Time variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to top of pageClick to jump to parent topicSetOutputParmTimeArray

Syntax

SetOutputParmTimeArray(parmName, &parmVal)

Description

Use the SetOutputParmTimeArray method to pass a Time array parameter value as output from any method you develop that corresponds to an Optimization PeopleCode plug-in transaction. You develop the transaction method in an application class that you derive from the OptBase application class.

Parameters

parmName

Specify the name of the parameter as it's defined for the Optimization PeopleCode plug-in transaction.

&parmVal

Specify a Time array variable that contains a value to be passed as output by the parameter.

Returns

A Boolean value: True if the method is successful, False otherwise.

Click to jump to parent topicOptInterface Class Methods

This section discusses the optimization methods for the OptInterface PeopleCode class. The methods are listed in alphabetical order.

Note. You can use the OptInterface class methods only within an application class that you extend from the OptBase application class, or within PeopleCode that you call from that application class. This ensures that the OptInterface PeopleCode runs only on the optimization engine.

Click to jump to top of pageClick to jump to parent topicActivateModel

Syntax

ActivateModel(ModelID, SolverSettingID)

Description

The ActivateModel method designates the specified model and solver setting as active. The model and the solver are initialized and populated with data from the current analytic instance.

Note. This method fails if the specified model (and by extension, one of its solver settings) is already active. If you want to activate a different solver setting for the same model, you must first deactivate the model.

See OptInterface class: DeactivateModel method.

Parameters

ModelID

Specify the name of the optimization model you want to activate. This must be the name of one of the models associated with the analytic type definition.

SolverSettingID

Specify the name of the solver setting you want to activate. This is the name you specified for the solver setting in the analytic type definition.

Returns

This method returns a constant value. Valid values are:

Value

Description

%OptInter_Success

Returned if method succeeds.

%OptInter_Fail

Returned if the solver fails to solve the problem.

Example

Local integer &result; Local OptInterface &oi = CreateOptInterface(); &result = &oi.ActivateModel("QE_PSA_MODEL", "abc");

Click to jump to top of pageClick to jump to parent topicActivateObjective

Syntax

ActivateObjective(Model_Name, Objective_Name)

Description

Use the ActivateObjective method to activate the specified objective for an optimization model.

Parameters

Model_Name

Specify the name of the model.

Objective_Name

Specify the name of the objective.

Returns

This method returns a constant value. Valid values are:

Value

Description

%OptInter_Success

Returned if method succeeds.

%OptInter_Fail

Returned if the solver fails to solve the problem.

Click to jump to top of pageClick to jump to parent topicDeactivateModel

Syntax

DeactivateModel(ModelID)

Description

The DeactivateModel method detaches the solver from the specified model.

Parameters

ModelID

Specify the name of the optimization model you want to deactivate. This must be the name of one of the models associated with the analytic type definition.

Returns

This method returns a constant value. Valid values are:

Value

Description

%OptInter_Success

Returned if method succeeds.

%OptInter_Fail

Returned if the solver fails to solve the problem.

Example

Local integer &result; Local OptInterface &oi = CreateOptInterface(); &result = &oi.DeactivateModel("QE_PSA_MODEL");

Click to jump to top of pageClick to jump to parent topicDumpMsgToLog

Syntax

DumpMsgToLog(LogSeverity, Message)

Description

The DumpMsgToLog method writes the specified status message to the optimization engine log file, with the specified severity.

Parameters

LogSeverity

Specify the severity level of the message, as one of the following system constants:

  • %Severity_Fatal

  • %Severity_Status

  • %Severity_Error

  • %Severity_Warn

  • %Severity_Info

  • %Severity_Trace1

  • %Severity_Trace2

Message

Specify as a string the text of the log message.

Returns

None.

Click to jump to top of pageClick to jump to parent topicFindRowNum

Syntax

FindRowNum(&Record [, startrow [, endrow [, field_list]]])

Where field_list is a list of field names in the form:

[fieldname1 [, fieldname2]]...

Description

The FindRowNum method determines the row number of a row in the datacache rowset. You provide a record with key values, and this method finds the row with the same key values and returns its row number.

Parameters

&Record

Specify a record with the same structure as the records that comprise the rowset, with its key fields populated.

startrow

Specify as an integer the starting row number of the search. Specify 0 to search from the first row in the rowset.

endrow

Specify as an integer the ending row number of the search. Specify 0 to search through the last row in the rowset.

fieldname

Specify the name of a field in the input record which contains a value to be matched. You can specify one or more field names, in any order.

Note. If you use this parameter, the fields specified here are used to search, instead of the record's key fields. Any value that doesn't correspond to a field name is ignored.

Returns

The row number of the row containing the specified key values, or 0 if no row is found.

Example

The following example searches the whole scroll to find the partial key OPT_SITE:

Local Record &rec = CreateRecord(Scroll.OPT_TRANSCOST); Local Optineterface &oi; &rec.OPT_SITE.value = "New York"; int nRowNum = &oi.FindRowNum(&rec, 0, 0, "OPT_SITE");

The following example searches from row 5 to row 15 with the full key values New York and San Jose:

Local Record &rec = CreateRecord(Scroll.OPT_TRANSCOST); Local Optineterface &oi; &rec.OPT_SITE.value = "New York"; &rec.OPT_STORE.value = "San Jose"; int nRowNum = &oi.FindRowNum(&rec, 5, 15);

Click to jump to top of pageClick to jump to parent topicGetSolution

Syntax

GetSolution(ModelID, varArrayID, skipZero [, KeyFieldNames, KeyFieldValues [, &Solution]])

Description

The GetSolution method retrieves the model solution values generated by the Solve method.

Parameters

ModelID

Specify as a string the name of the optimization model for which you want the solution. This is the name used for the model definition in Application Designer.

varArrayID

Specify as a string the name of the variable array being optimized. Your application documentation should provide this name.

skipZero

Indicate whether solutions with a value of zero should be fetched. This parameter takes a Boolean value:

  • True: Don't fetch solutions with a zero value. This can increase the performance of the GetSolution method if zero values aren't meaningful.

  • False: Do fetch solutions with a zero value.

KeyFieldNames and KeyFieldValues

Specify a set of key field names as an array of string and a set of key field values as an equal length array of ANY, with one key field value corresponding to each key field name. You use these arrays to restrict the set of returned solutions. Solutions are returned only for model variables with the specified key field values.

Note. If you provide either of these arrays, you must provide both. You can include each parameter from the variable array at most only once.

&Solution

Specify a rowset to contain the solutions.

Returns

This method returns a constant value. Valid values are:

Value

Description

%OptInter_Success

Returned if method succeeds.

%OptInter_Fail

Returned if the solver fails to solve the problem.

Example

Local array of string &strArray; Local array of any &valArray; Local integer &index; Local Rowset &rowSet; Local integer &result; Local string &modelId = "QE_PSA_MODEL"; Local string &varArrayName = "X"; Local boolean &bSkipZero = True; Local OptInterface &oi = CreateOptInterface(); &strArray = CreateArrayRept("", 0); &valArray = CreateArrayAny(); &rowSet = CreateRowset(Record.QEOPT_VAL_X_WRK); &strArray [1] = "EMPLID"; &valArray [1] = 1; &strArray [2] = "ORDER_ID"; &valArray [2] = 23; /* fetch only the part of the solution where EMPLID = 1 and ORDER_ID = 23 */ &result = &oi.GetSolution(&modelId, &varArrayName, &bSkipZero, &strArray, &valArray, &rowSet);

Click to jump to top of pageClick to jump to parent topicGetSolutionDetail

Syntax

GetSolutionDetail(ModelID, SolutionType, Name, &Solution)

Description

The GetSolutionDetail method retrieves the model solution detail of the specified type generated by the Solve method. You can retrieve dual value, slack value, or reduced cost information.

Parameters

ModelID

Specify as a string the name of the optimization model for which you want the solution detail. This is the name used for the model definition in Application Designer.

SolutionType

Specify a system constant indicating the type of solution detail you want to retrieve. The value you specify here determines the content of the Name and &Solution parameters.

  • %OPT_DUAL: Retrieve the dual value attributes of the specified constraint block.

  • %OPT_SLACK: Retrieve the slack value attributes of the specified constraint block.

  • %OPT_RCOST: Retrieve the reduced cost attributes of the specified variable array.

Name

If you specified a SolutionType of %OPT_DUAL or %OPT_SLACK, specify here the name of a constraint block from the active model.

If you specified a SolutionType of %OPT_RCOST, specify here the name of a variable array from the active model.

&Solution

Specify a rowset to contain the solution details. The rowset should have the same key fields as the constraint block or the variable array you specified with the Name parameter.

Returns

This method returns a constant value. Valid values are:

Value

Description

%OptInter_Success

Returned if method succeeds.

%OptInter_Fail

Returned if solver fails to solve the problem.

Example

Local Rowset &dual_rowset; Local integer &result; Local OptInterface &oi = CreateOptInterface(); Local string &modelId = "QE_PSA_MODEL"; Local string &varArrayName = "X"; Local string &constrName = "Constraint_1"; /* fetch dual values for Contraint "Constraint_1" in a rowset based on the QEOPT_C1_WRK record */ &dual_rowset = CreateRowset(Record.QEOPT_C1_WRK); &result = &oi.GetSolutionDetail(&modelId, %Opt_Dual, &constrName, &dual_rowset);

Click to jump to top of pageClick to jump to parent topicIsModelActive

Syntax

IsModelActive(ModelID)

Description

Use the IsModelActive method to determine if the model specified by ModelId is active before it is used.

Parameters

ModelID

Specify the model ID as a string. This is the name used for the model definition in Application Designer.

Returns

A Boolean value: true if the model is active, false otherwise.

Click to jump to top of pageClick to jump to parent topicRestoreBounds

Syntax

RestoreBounds(modelID [,varArrayID])

Description

The RestoreBounds method returns the bounding values of the specified variable array or arrays to the current settings in the specified model.

If you previously called the SetVariableBounds method with the changeModelBounds parameter set to true for any variable or variable array, those bounding values still apply.

Parameters

modelID

Specify as a string the name of the optimization model for which you want to restore the bounding values. This is the name used for the model definition in Application Designer.

varArrayID

Specify as a string the name of a variable array for which you want to restore the bounding values. Your application documentation should provide this name. If you don't specify a variable array name, the bounding values are restored for all variable arrays in the specified model.

Returns

%OptInter_Success if the method succeeds, %OptInter_Fail otherwise.

Click to jump to top of pageClick to jump to parent topicSetVariableBounds

Syntax

SetVariableBounds(modelID, varArrayID, boundType, lowerBound, upperBound, &keyRecord [, changeModelBounds])

Description

The SetVariableBounds method overrides the bounding values specified for a model variable array, or for a variable within the array.

Parameters

modelID

Specify as a string the name of the optimization model for which you want to override the bounding values. This is the name used for the model definition in Application Designer.

varArrayID

Specify as a string the name of the variable array being optimized. Your application documentation should provide this name.

boundType

Specify a system constant indicating which bounding values to override. The value you specify here determines how the lowerBound and upperBound parameters are applied to the specified model.

  • %OPT_LOWER_BOUND: Override only the lower bound as specified by the lowerBound parameter. The upperBound parameter is ignored.

  • %OPT_UPPER_BOUND: Override only the upper bound as specified by the upperBound parameter. The lowerBound parameter is ignored.

  • %OPT_BOUND_BOTH: Override both the lower bound and the upper bound as specified by the lowerBound and upperBound parameters, respectively.

lowerBound

Specify as a number the lower bound that should be applied to a variable or a variable array if the boundType parameter permits the override. You can also set this parameter to one of the following system constants:

upperBound

Specify as a number the upper bound that should be applied to a variable or a variable array if the boundType parameter permits the override. You can also set this parameter to one of the following system constants:

&keyRecord

Specify a record with the same key fields as the variable array being optimized. To override the bounding values specified for a single variable within the array, populate the record's key fields to specify the variable. To override the bounding values specified for the entire variable array, set all of the record's fields to a null value.

Note. You must either provide values for all keys, or set them all to null values.

changeModelBounds

Specify a Boolean value:

  • true: Indicates that the specified model should be updated in memory to reflect the specified variable bounds. Any analytic instance that invokes this model from the active optimization engine is affected by these settings, which are propagated to the solver in memory. This is the default value if you omit this parameter.

  • false: Indicates that the specified model should not be updated in memory, and that the specified variable bounds apply only to the next time the Solve method is called.

Returns

%OptInter_Success if the method succeeds, %OptInter_Fail otherwise.

Example

Local Record &rec; Local integer &result; Local OptInterface &oi = CreateOptInterface(); Local float &objval = 0.0; Local string &modelId = "QE_PSA_MODEL"; Local string &varArrayName = "X"; Local float &lb = 0.0; Local float &ub = 0.0; &rec = CreateRecord(Record.QEOPT_VAL_X_WRK); &rec.QEOPT_RESINDEX.Value = 1; &rec.QEOPT_SOLINDEX.Value = 2; &rec.QEOPT_TIMEINDEX.Value = 3; &result = &oi.SetVariableBounds(&modelId, &varArrayName, %Opt_Upper_Bound, &lb, &ub, &rec, False);

Click to jump to top of pageClick to jump to parent topicSetVariableType

Syntax

SetVariableType(modelID, varArrayID, varType)

Description

Use the SetVariableType method to change the data type of a model variable array.

Parameters

ModelID

Specify as a string the name of the optimization model for which you want to change the variable type. This must be the name of one of the models associated with the analytic type definition.

varArrayID

Specify as a string the name of the variable array for which you want to change the variable type. Your application documentation should provide this name.

varType

Specify one of the following system constants representing the new variable type:

  • %Opt_Var_Cont: Represents a continuous variable type, which can be any floating point value.

  • %Opt_Var_Bin: Represents a binary variable type, for which the value can be only 0 or 1.

  • %Opt_Var_Int: Represents an integer variable type, which can be any integer.

Returns

%OptInter_Success if the method succeeds, %OptInter_Fail otherwise.

Example

Local OptInterface &oi = CreateOptInterface(); Local string &varArrayName = "X"; Local integer &result; &result = &oi.SetVariableType("QE_PSA_MODEL", &varArrayName, %Opt_Var_Bin); If (&result <> %OptInter_Success) Then &oi.DumpMsgToLog(%Severity_Status, "Failed to change variable type "); End-If;

Click to jump to top of pageClick to jump to parent topicSolve

Syntax

Solve(modelID, SolutionType [, &objValue [, name-value_pairs]])

Where name-value_pairs is a list of solver setting parameter values in the form:

[parmname1, parmvalue1 [, parmname2, parmvalue2]]...

Description

The Solve method solves the specified model using the currently active solver settings, and provides an objective value as the solution output. You can override the solver setting parameters. The returned solution status is a predefined system constant.

Parameters

ModelID

Specify as a string the name of the optimization model you want to solve. This is the name used for the model definition in Application Designer.

SolutionType

Specify a system constant indicating the type of solution detail you want the model to be solved for.

  • %OPT_DUAL: Generate dual value attributes.

  • %OPT_SLACK: Generate slack value attributes.

  • %OPT_RCOST: Generate reduced cost attributes.

You can also combine any or all of these system constants, by connecting them with a plus sign (+), for example: %OPT_DUAL + %OPT_RCOST.

&objValue

Specify a reference to a variable of type float. This variable contains the output objective value produced by the solver upon successfully solving the specified optimization model.

parmname and parmvalue

Specify a solver setting parameter ID and value to override the original value you specified for the solver setting in the analytic type definition. You can override any or all of the solver setting parameter values.

See Configuring Models for Optimization.

Returns

One of the following system constants:

%OptInter_Fail: The solver fails to solve the problem.

%Opt_Optimal: The solution is optimal.

%Opt_Infeasible: The solution is infeasible.

%Opt_Unbounded: The solution is unbounded.

%Opt_Timeup: The solver reached the time limit specified in the solver setting.

%Opt_Iterlimit: The solver reached the limit on the number of iterations specified in the solver setting.

%Opt_LP_Max_Sols: The solver generated maximum number of solutions without improvement.

%Opt_Idle: The solution shows no improvement in a specified time limit.

%Opt_Unknown: The solver status is unknown.

%Opt_MIP_NumSolutions: The specified number of solutions corresponding to an MIP solver reached.

%Opt_MIP_NumNodes: The specified number of nodes corresponding to an MIP solver reached.

%Opt_Aborted: The solver aborted.

%Opt_User_Exit: A user exit was encountered.

%Opt_First_LP_NoOpt: While solving an MIP, the first LP solution obtained was not optimal.

Example

Following is an example of the basic use of the Solve method:

Local OptInterface &oi = CreateOptInterface(); Local float &objval = 0.0; Local integer &result; Local string &modelId = "QE_PSA_MODEL"; Local string &varArrayName = "X"; Local integer &solType; &solType = %Opt_RCost + %Opt_Dual + %Opt_Slack; /* Solve the problem */ &result = &oi.Solve("QE_PSA_MODEL", &solType, &objval); If & result = %Opt_Optimal Then &oi.DumpMsgToLog(%Severity_Warn, " Solution Status = " Optimal !!!"); Else &oi.DumpMsgToLog(%Severity_Warn, " Solution Status = " | &result ); End-If;

Following is an example of a solver setting parameter override:

Local OptInterface &oi = CreateOptInterface(); Local float &objval = 0.0; Local integer &result; /* This overrides the solver setting for MPS_Filename and generates an MPS file called myfile.mps instead of the name specified in the current solver setting parameter. */ &result = &oi.Solve("QE_PSA_MODEL", %Opt_Primal, &objval, "MPS_FileName", "myfile");