# Reduce Exchange Between Client Session and Server Session¶

As shown in Deploy an Application on AIMMS PRO, part of the overhead in solving is creating a case and transferring it, once from the client session to the server session and once back. Especially, for short solves, the overhead can be relatively large. To reduce this overhead, we’ll reduce the number of identifiers that need to be passed between these sessions.

## The identifiers needed by the server session¶

There are three groups of identifiers needed by the server session that can be provided by the client session:

1. The sets and parameters used in defining mathematical program instances to be solved
2. The sets and parameters used in pre-processing and post-processing these mathematical programs
3. The subset of AllIdentifiers that contains those identifiers that comprise the solution; in other words those identifiers that need to be passed back to the client session.

In the declaration below, the variables and constraints that make up the mathematical program FlowShopModel are the sets sFlowshopConstraints and sFlowshopVariables.

MathematicalProgram FlowShopModel {
Objective: TimeSpan;
Direction: minimize;
Constraints: sFlowshopConstraints;
Variables: sFlowshopVariables;
}
Set sFlowshopConstraints {
SubsetOf: AllConstraints;
Definition: AllConstraints * Flowshop_Mathematical_Program_Declarations;
}
Set sFlowshopVariables {
SubsetOf: AllVariables;
Definition: AllVariables * Flowshop_Mathematical_Program_Declarations;
}


To determine which identifiers make up the mathematical program instance we need to know which identifiers are referenced in the variable and constraint definitions. We use the function ReferencedIdentifiers for this as follows:

sInputIds :=
! Identifiers from mathematical program:
sFlowshopConstraints + sFlowshopVariables + data { TimeSpan } +
! Identifiers from the section where the solution process is coded:
Solution_Work_horses ;

sInputIds :=
sInputIds + ! For bounds on variables, scaling factors, etc
! Ensure that all identifiers referenced in these variables
! and constraints are in the input case.
ReferencedIdentifiers( sInputIds, AllAttributeNames, recursive: 1 ) +
! Stash list of identifiers to be returned.
data { sOutputIds } ;


Now we only to construct the set of output identifiers, i.e. those identifiers that should be in the case send from the server session to the client session. The client session only needs the Gantt Chart starts and durations. So that is simply:

sOutputIds := data { pGCJobStart, pGCJobDuration };


Now we have constructed the sets of identifiers that need to be passed from the client session to the server session (sInputIds) and the set of identifiers to be passed from the server session to the client session (sOutputIds), we need to pass this information to AIMMS PRO, such that pro::DelegateToServer correctly handles this. For this purpose, AIMMS PRO declares the following sets: pro::ManagedSessionInputCaseIdentifierSet and pro::ManagedSessionOutputCaseIdentifierSet.

1. The pro::ManagedSessionInputCaseIdentifierSet needs to be assigned before calling the procedure pro::DelegateToServer, for instance as follows:

pro::ManagedSessionInputCaseIdentifierSet := sInputIds ;

2. The pro::ManagedSessionOutputCaseIdentifierSet needs to be assigned during the execution of the server session. For instance as follows:

if pro::DelegateToServer( waitForCompletion: 1,
return 1;
endif ;

prDoSolve();
pro::ManagedSessionOutputCaseIdentifierSet := sOutputIds ;


## Summary¶

In this article, we’ve shown how to reduce the overhead of creating and communicating cases between the client session and the server session.

1. See also the section on input and output case definitions in AIMMS PRO documentation
2. The descriptions of the functions ReferencedIdentifiers and SectionIdentifiers in AIMMS PRO Function Reference .

You can download the example: 2a. Flow Shop - ReducedCases.