use of org.iobserve.analysis.data.EntryCallSequenceModel in project iobserve-analysis by research-iobserve.
the class OverlappingIterationReference method getModel.
/**
* Creates a reference model that contains a loop element. The user sessions contain iterated
* call sequences that share overlapping calls. Thereby, one iterated sequence consists of more
* calls than the other. Thus, it can be checked whether the approach transforms the iterated
* call sequence that consists of more calls to a loop (RQ-1.4)
*
* @param referenceUsageModelFileName
* file name of the reference model to store its result
* @param repositoryLookupModelProvider
* repository model provider
* @param correspondenceModel
* correspondence model
*
* @return a reference usage model and corresponding user sessions
* @throws IOException
* on error
*/
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final ICorrespondence correspondenceModel) throws IOException {
// Creates a random number of user sessions and random model element parameters. The user
// sessions' behavior will be created according to the reference usage model and
// subsequently the user sessions are used to create a usage model. The created usage model
// is matched against the reference usage model.
final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 1);
// One of the iterated sequences is iterated twice and one is iterated three times. The
// number of iterations is set randomly.
final int loopCount1 = TestHelper.getRandomInteger(3, 2);
final int lengthOfSequence1 = 2 * loopCount1;
final int loopCount2;
if (loopCount1 == 3) {
loopCount2 = 2;
} else {
loopCount2 = 3;
}
final int lengthOfSequence2 = 2 * loopCount2;
final ReferenceElements referenceElements = new ReferenceElements();
final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
// In the following the reference usage model is created
AbstractUserAction lastAction;
final UsageModel usageModel = UsageModelFactory.createUsageModel();
final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
final Start start = UsageModelFactory.createStart("");
UsageModelFactory.addUserAction(scenarioBehaviour, start);
final Stop stop = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(scenarioBehaviour, stop);
// According to the randomly set number of iterations the sequence that is iterated three
// times is represented by a loop element. The other sequence is represented by a sequence
final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
if (lengthOfSequence1 >= lengthOfSequence2) {
UsageModelFactory.connect(start, loop);
final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmLoopIteration.setSpecification(String.valueOf(loopCount1));
// Set number of loops
loop.setLoopIteration_Loop(pcmLoopIteration);
final Start loopStart = UsageModelFactory.createStart("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStart);
final Stop loopStop = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStop);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, loopStart, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
UsageModelFactory.connect(lastAction, loopStop);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, loop, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, lastAction, scenarioBehaviour);
UsageModelFactory.connect(lastAction, stop);
} else {
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, start, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, lastAction, scenarioBehaviour);
UsageModelFactory.connect(lastAction, loop);
final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmLoopIteration.setSpecification(String.valueOf(loopCount2));
// Set number of loops
loop.setLoopIteration_Loop(pcmLoopIteration);
final Start loopStart = UsageModelFactory.createStart("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStart);
final Stop loopStop = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStop);
lastAction = loopStart;
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, lastAction, scenarioBehaviour);
UsageModelFactory.connect(lastAction, loopStop);
UsageModelFactory.connect(loop, stop);
}
OverlappingIterationReference.createMatchingEntryAndExitEvents(entryCallSequenceModel, lengthOfSequence1, lengthOfSequence2, loopCount1, loopCount2);
// Saves the reference usage model and sets the usage model and the EntryCallSequenceModel
// as the reference elements. Our approach is now executed with the EntryCallSequenceModel
// and the resulting usage model can be matched against the reference usage model
TestHelper.saveModel(usageModel, referenceUsageModelFileName);
referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
referenceElements.setUsageModel(usageModel);
return referenceElements;
}
use of org.iobserve.analysis.data.EntryCallSequenceModel in project iobserve-analysis by research-iobserve.
the class SimpleBranchReference method getModel.
/**
* Creates a reference model that contains a branch element. Accordingly, user sessions whose
* call sequences differ from each other at the position of the branch are created.(RQ-1.2)
*
* @param referenceModelFileName
* file name of the reference model to store its result
* @param repositoryLookupModelProvider
* repository model provider
* @param correspondenceModel
* correspondence model
*
* @return a reference usage model and corresponding user sessions
* @throws IOException
* on error
*/
public static ReferenceElements getModel(final String referenceModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final ICorrespondence correspondenceModel) throws IOException {
// Create a random number of user sessions and random model element parameters. The user
// sessions' behavior will be created according to the reference usage model and
// subsequently the user sessions are used to create a usage model. The created usage model
// is matched against the reference usage model. The minimum number of user sessions is set
// dependently from the random number of branch transitions, because it must be ensured that
// each branch transition is represented within the user sessions.
final int numberOfBranchTransitions = TestHelper.getRandomInteger(5, 2);
final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 10 * numberOfBranchTransitions);
final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
// In the following the reference usage model is created
Optional<Correspondent> correspondent;
final UsageModel usageModel = UsageModelFactory.createUsageModel();
final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
AbstractUserAction lastAction = start;
// Creates the branch element and the branch transitions according to the random number of
// branch transitions
final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", scenarioBehaviour);
UsageModelFactory.connect(start, branch);
// the alternative call sequences
for (int i = 0; i < numberOfBranchTransitions; i++) {
final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branch);
final ScenarioBehaviour branchTransitionBehaviour = branchTransition.getBranchedBehaviour_BranchTransition();
final Start startBranchTransition = UsageModelFactory.createAddStartAction("", branchTransitionBehaviour);
final Stop stopBranchTransition = UsageModelFactory.createAddStopAction("", branchTransitionBehaviour);
lastAction = startBranchTransition;
if (i >= 0 && i < 5) {
correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
if (correspondent.isPresent()) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondent.get());
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
if (i == 0) {
correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[1], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[1]);
} else {
correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[0], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[0]);
}
if (correspondent.isPresent()) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondent.get());
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, stopBranchTransition);
}
correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[2], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[2]);
if (correspondent.isPresent()) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondent.get());
UsageModelFactory.addUserAction(scenarioBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(branch, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, stop);
final List<Integer> branchTransitionCounter = SimpleBranchReference.computeBranchTransitions(entryCallSequenceModel, branch, numberOfBranchTransitions);
// the randomly created user sessions
for (int i = 0; i < branch.getBranchTransitions_Branch().size(); i++) {
branch.getBranchTransitions_Branch().get(i).setBranchProbability((double) branchTransitionCounter.get(i) / numberOfConcurrentUsers);
}
return SimpleBranchReference.saveReferenceElements(usageModel, referenceModelFileName, entryCallSequenceModel);
}
use of org.iobserve.analysis.data.EntryCallSequenceModel in project iobserve-analysis by research-iobserve.
the class ClusteringEvaluation method createCallSequenceModelWithVaryingUserGroups.
/**
* Creates for each user group user sessions with random behavior according to the
* BehaviorModels and subsumes the user sessions within an EntryCallSequenceModel.
*
* @throws IOException
*/
private void createCallSequenceModelWithVaryingUserGroups() throws IOException {
final List<UserSession> userSessionsOfGroupCustomer = this.getUserSessions(ClusteringEvaluation.NUMBER_OF_USER_SESSIONS_OF_USER_GROUP_CUSTOMER, ClusteringEvaluation.CUSTOMER_TAG);
final List<UserSession> userSessionsOfGroupStockManager = this.getUserSessions(ClusteringEvaluation.NUMBER_OF_USER_SESSIONS_OF_USER_GROUP_STOCK_MANAGER, ClusteringEvaluation.STOCK_MANAGER_TAG);
final List<UserSession> userSessionsOfGroupStoreManager = this.getUserSessions(ClusteringEvaluation.NUMBER_OF_USER_SESSIONS_OF_USER_GROUP_STORE_MANAGER, ClusteringEvaluation.STORE_MANAGER_TAG);
this.createCallSequencesForUserGroupCustomer(userSessionsOfGroupCustomer);
this.createCallSequencesForUserGroupStockManager(userSessionsOfGroupStockManager);
this.createCallSequencesForUserGroupStoreManager(userSessionsOfGroupStoreManager);
final List<UserSession> userSessions = new ArrayList<>();
userSessions.addAll(userSessionsOfGroupStockManager);
userSessions.addAll(userSessionsOfGroupStoreManager);
userSessions.addAll(userSessionsOfGroupCustomer);
final long seed = 5;
Collections.shuffle(userSessions, new Random(seed));
this.entryCallSequenceModel = new EntryCallSequenceModel(userSessions);
}
use of org.iobserve.analysis.data.EntryCallSequenceModel in project iobserve-analysis by research-iobserve.
the class SimpleLoopReference method getModel.
/**
* Creates a reference model that contains a loop element. Accordingly, user sessions whose call
* sequences contain iterated calls are created.(RQ-1.3)
*
* @param referenceUsageModelFileName
* reference usage model file name
* @param repositoryLookupModelProvider
* repository model provider
* @param correspondenceModel
* correspondence model
*
* @return the reference usage model and a corresponding EntryCallSequenceModel
* @throws IOException
* on error
*/
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final ICorrespondence correspondenceModel) throws IOException {
// Create a random number of user sessions and random model element parameters. The user
// sessions' behavior will be created according to the reference usage model and
// subsequently the user sessions are used to create a usage model. The created usage model
// is matched against the reference usage model
final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 1);
final int loopCount = TestHelper.getRandomInteger(5, 2);
final int numberOfIteratedCalls = TestHelper.getRandomInteger(5, 1);
final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
final ReferenceElements referenceElements = new ReferenceElements();
// In the following the reference usage model is created
AbstractUserAction lastAction;
final UsageModel usageModel = UsageModelFactory.createUsageModel();
final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
// A loop is created and the loop count is set
final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
UsageModelFactory.connect(start, loop);
final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmLoopIteration.setSpecification(String.valueOf(loopCount));
loop.setLoopIteration_Loop(pcmLoopIteration);
UsageModelFactory.connect(loop, stop);
// The EntryLevelSystemCalls that are iterated are added to the loop element
final Start loopStart = UsageModelFactory.createAddStartAction("", loop.getBodyBehaviour_Loop());
final Stop loopStop = UsageModelFactory.createAddStopAction("", loop.getBodyBehaviour_Loop());
lastAction = loopStart;
Optional<Correspondent> optionCorrespondent;
// iterated calls to the loop
for (int i = 0; i < numberOfIteratedCalls; i++) {
if (i >= 0 && i < 5) {
optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
if (optionCorrespondent.isPresent()) {
final Correspondent correspondent = optionCorrespondent.get();
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondent);
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
}
UsageModelFactory.connect(lastAction, loopStop);
// According to the reference usage model user sessions are created that exactly represent
// the user behavior of the reference usage model. The entry and exit times enable that the
// calls within the user sessions are ordered according to the reference usage model
int entryTime = 1;
int exitTime = 2;
for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
entryTime = 1;
exitTime = 2;
// number of iterated calls
for (int k = 0; k < loopCount; k++) {
for (int j = 0; j < numberOfIteratedCalls; j++) {
EntryCallEvent entryCallEvent = null;
if (j >= 0 && j < 5) {
entryCallEvent = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[j], ReferenceUsageModelBuilder.CLASS_SIGNATURE[j], String.valueOf(i), "hostname");
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
entryCallSequenceModel.getUserSessions().get(i).add(entryCallEvent, true);
entryTime = entryTime + 2;
exitTime = exitTime + 2;
}
}
}
// Saves the reference usage model and sets the usage model and the EntryCallSequenceModel
// as the reference elements. Our approach is now executed with the EntryCallSequenceModel
// and the resulting usage model can be matched against the reference usage model
TestHelper.saveModel(usageModel, referenceUsageModelFileName);
referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
referenceElements.setUsageModel(usageModel);
return referenceElements;
}
use of org.iobserve.analysis.data.EntryCallSequenceModel in project iobserve-analysis by research-iobserve.
the class UserGroupExtraction method extractUserGroups.
/**
* Function to extract user groups.
*/
public void extractUserGroups() {
final ClusteringPrePostProcessing clusteringProcessing = new ClusteringPrePostProcessing();
final XMeansClustering xMeansClustering = new XMeansClustering();
ClusteringResults xMeansClusteringResults;
/**
* 1. Extraction of distinct system operations. Creates a list of the distinct operation
* signatures occurring within the entryCallSequenceModel. It is required to transform each
* user session to counts of its called operations. The counts are used to determine the
* similarity between the user sessions
*/
final List<String> listOfDistinctOperationSignatures = clusteringProcessing.getListOfDistinctOperationSignatures(this.entryCallSequenceModel.getUserSessions());
/**
* 2. Transformation to the call count model. Transforms the call sequences of the user
* sessions to a list of counts of calls that state the number of calls of each distinct
* operation signature for each user session
*/
final List<UserSessionAsCountsOfCalls> callCountModel = clusteringProcessing.getCallCountModel(this.entryCallSequenceModel.getUserSessions(), listOfDistinctOperationSignatures);
/**
* 3. Clustering of user sessions. Clustering of the user sessions whose behavior is
* represented as counts of their called operation signatures to obtain user groups
*/
final Instances instances = xMeansClustering.createInstances(callCountModel, listOfDistinctOperationSignatures);
/*
* The clustering is performed 5 times and the best result is taken. The quality of a
* clustering result is determined by the value of the sum of squared error (SSE) of the
* clustering. The lower the SSE is the better the clustering result.
*/
for (int i = 0; i < 5; i++) {
xMeansClusteringResults = xMeansClustering.clusterSessionsWithXMeans(instances, this.numberOfUserGroupsFromInputUsageModel, this.varianceOfUserGroups, i);
if (this.clusteringResults == null) {
this.clusteringResults = xMeansClusteringResults;
} else if (xMeansClusteringResults.getClusteringMetrics().getSumOfSquaredErrors() < this.clusteringResults.getClusteringMetrics().getSumOfSquaredErrors()) {
this.clusteringResults = xMeansClusteringResults;
}
}
/**
* 4. Obtaining the user groups' call sequence models. Creates for each cluster resp. user
* group its own entry call sequence model that exclusively contains its assigned user
* sessions
*/
final List<EntryCallSequenceModel> entryCallSequenceModelsOfXMeansClustering = clusteringProcessing.getForEachUserGroupAnEntryCallSequenceModel(this.clusteringResults, this.entryCallSequenceModel);
/**
* 5. Obtaining the user groups' workload intensity. Calculates and sets for each user group
* its specific workload intensity parameters
*/
clusteringProcessing.setTheWorkloadIntensityForTheEntryCallSequenceModels(entryCallSequenceModelsOfXMeansClustering, this.isClosedWorkload);
/**
* Sets the resulting entryCallSequenceModels that can be retrieved via the getter method
*/
this.entryCallSequenceModelsOfUserGroups = entryCallSequenceModelsOfXMeansClustering;
}
Aggregations