NOTE: See Writing a Custom Scheduler Rule for a summary of the steps required to create custom rules. For more details about the functions described in this topic, see the Simulation Tailoring Support Function Reference (available for download from the Support web site, on the documentation page for the Infor APS Virtual Planning/Simulation product).
Resource allocation rules are used to decide which resources from a resource group the Scheduler will use when it allocates resources to a load. They are also used for reallocating resources if reallocation has been enabled for the group.
The function can have any name that is not a standard user-callable function name.
#include "factor.h" void myrule(gp, nu, ldp, mlist) RESGRP *gp; /* pointer to resource group. */ int nu; /* number of units required. */ LOAD *ldp; /* pointer to the load. */ CSLIST *mlist; /* current selection list. */
The function must accept four arguments in the following order:
Group members can be added and removed from the list of selected resources (mlist) using the system support functions seadsl and sermsl, respectively. To add group members to the list, use function seadsl as follows:
void seadsl(CSLIST *mlist, RESMEMB *rmp)
To remove group members from the list, use function sermsl as follows:
void sermsl(CSLIST *mlist, RMTAG *rmt)
The function should return nothing (Type: void).
Here is an example of a rule to select available resource group members on the basis of least mean utilization:
void rgsr (RESGRP *gp, int nu, LOAD *ldp, CSLIST *mlist) /*----------------------------------------------------------------- Function to process resource group selection code 3, select required number of member resources that have the least mean utilizations (as a fraction of capacity). NOTES: * Ties are broken by selecting the first in the order listed in the group. * This function requires that resource statistics be enabled. Any resource which does not have statistics enabled is assumed to have a utilization of zero. Thus if all resource statistics are disabled, this defaults to rule 0. * This function uses seaars, which includes must complete and maxOT in its considerations, to determine the availability of each member resource. ARGS: gp - pointer to resource group to select member from nu - number of units required from selected member ldp - pointer to load to which resource will be allocated mlist - list to hold selected RESMEMB's RETURNS: void -----------------------------------------------------------------*/ { int i, j, *avail; double min, *util; RESMEMB *minp, *rmp; /* Allocate arrays for availability and utilization. */ avail = (int *) malloc(sizeof(int) * csszls(gp->rgrsls)); if ( avail == NULL ) { seferr(0, "Out of Memory"); } util = (double *) malloc(sizeof(double) * csszls(gp->rgrsls)); if ( util == NULL ) { seferr(0, "Out of Memory"); } /* Compute availability and utilization. */ for ( rmp = (RESMEMB *) csfsls(gp->rgrsls), j = 0; rmp != NULL; rmp = (RESMEMB *) csnxls((CSENTITY *) rmp), j++ ) { avail[j] = seaars(rmp->rmres, ldp); util[j] = seutrs(rmp->rmres); } /* For the required number of units */ for ( i = csszls(mlist); i < nu; i++ ) { /* For each resource which is available. */ minp = NULL; for ( rmp = (RESMEMB *) csfsls(gp->rgrsls), j = 0; rmp != NULL; rmp = (RESMEMB *) csnxls((CSENTITY *) rmp), j++ ) { if ( (! rmp->rmres->rsselfg) && (avail[j] > 0) ) { /* Save if min. */ if ( (minp == NULL) || (util[j] < min) ) { minp = rmp; min = util[j]; } } } if ( minp == NULL ) { break; } seadsl(mlist, minp); } free(avail); free(util); return; }
To make your custom resource allocation function available to the Scheduler, you must "install" it from the ucini1 function by calling the function sedfgs. The function sedfgs has two arguments in the following order:
For example, to install the above example rule "rgsr" in rule position 39:
sedfgs (39, rgsr);
Compiling and Linking Custom Scheduler Rules