use of org.iobserve.analysis.userbehavior.ReferenceElements in project iobserve-analysis by research-iobserve.
the class SimpleSequenceReference method getModel.
/**
* Creates a reference model that contains a simple sequence of calls. Accordingly, user
* sessions whose call sequences contain a simple call sequence are created. (RQ-1.1) It is also
* used to evaluate the accuracy of workload specifications. Therefore, varying workload is
* generated by random entry and exit times of the user sessions, a random number of user
* sessions for a closed workload specification and a random mean inter arrival time for an open
* workload specification (RQ-1.9)
*
* @param referenceUsageModelFileName
* file name of the reference model to store its result
* @param repositoryLookupModel
* repository lookup model
* @param correspondenceModel
* correspondence model
* @param thinkTime
* of a closed workload.
* @param isClosedWorkload
* decides whether a closed or an open workload is created
* @return the reference usage model, a corresponding EntryCallSequenceModel and a reference
* workload
* @throws IOException
* on error
*/
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel, final int thinkTime, final boolean isClosedWorkload) 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 numberOfUsersSessions = TestHelper.getRandomInteger(200, 1);
final int numberOfCalls = TestHelper.getRandomInteger(5, 1);
final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfUsersSessions));
final ReferenceElements referenceElements = new ReferenceElements();
// In the following the reference usage model is created
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;
Optional<Correspondent> correspondent;
// created
for (int i = 0; i < numberOfCalls; i++) {
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(repositoryLookupModel, correspondent.get());
UsageModelFactory.addUserAction(scenarioBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
}
UsageModelFactory.connect(lastAction, stop);
// 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 are set randomly
// to evaluate a closed workload. For the evaluation of an open workload the mean inter
// arrival time is set randomly
int entryTime = 0;
int exitTime = 1;
final int meanInterArrivalTime = TestHelper.getRandomInteger(30, 1);
for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
if (isClosedWorkload) {
entryTime = TestHelper.getRandomInteger(30, 1);
exitTime = entryTime + 1;
} else {
entryTime += meanInterArrivalTime;
exitTime += meanInterArrivalTime;
}
for (int k = 0; k < numberOfCalls; k++) {
EntryCallEvent entryCallEvent = null;
if (k >= 0 && k < 5) {
entryCallEvent = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[k], ReferenceUsageModelBuilder.CLASS_SIGNATURE[k], 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, the EntryCallSequenceModel
// and the workload 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. Alike, the by our approach calculated workload can be matched against the
// reference workload. This is done by {@link
// org.iobserve.analysis.userbehavior.test.WorkloadEvaluation}
TestHelper.saveModel(usageModel, referenceUsageModelFileName);
referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
referenceElements.setUsageModel(usageModel);
referenceElements.setMeanInterArrivalTime(meanInterArrivalTime + numberOfCalls * 2);
referenceElements.setMeanConcurrentUserSessions(SimpleSequenceReference.calculateTheNumberOfConcurrentUsers(entryCallSequenceModel.getUserSessions()));
return referenceElements;
}
use of org.iobserve.analysis.userbehavior.ReferenceElements in project iobserve-analysis by research-iobserve.
the class BranchWithinBranchReference method getModel.
/**
* It creates a reference usage model that contains nested branches. Accordingly, user sessions
* whose call sequences differ from each other at the positions of the branches are
* created.(RQ-1.5)
*
* @param referenceUsageModelFileName
* file name of the reference model to store its result
* @param usageModelBuilder
* usage model builder
* @param repositoryLookupModel
* 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 UsageModelFactory usageModelBuilder, final RepositoryLookupModelProvider repositoryLookupModel, 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 numberOfTransitionsOfExteriorBranch = TestHelper.getRandomInteger(3, 2);
final int numberOfTransitionsOfInteriorBranches = TestHelper.getRandomInteger(3, 2);
final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 10 * numberOfTransitionsOfExteriorBranch);
final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
final ReferenceElements referenceElements = new ReferenceElements();
final List<Integer> branchTransitionCounter = new ArrayList<>();
final List<List<Integer>> listOfbranchTransitionCounterInterior = new ArrayList<>();
BranchWithinBranchReference.createUserSessions(branchTransitionCounter, listOfbranchTransitionCounterInterior, numberOfTransitionsOfExteriorBranch, numberOfTransitionsOfInteriorBranches, entryCallSequenceModel);
final UsageModel usageModel = BranchWithinBranchReference.createTheReferenceModel(usageModelBuilder, repositoryLookupModel, correspondenceModel, numberOfTransitionsOfExteriorBranch, numberOfTransitionsOfInteriorBranches, numberOfConcurrentUsers, branchTransitionCounter, listOfbranchTransitionCounterInterior);
// 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.userbehavior.ReferenceElements in project iobserve-analysis by research-iobserve.
the class LoopWithinBranchReference method getModel.
/**
* It creates a reference usage model that contains loops within branches. Accordingly, user
* sessions whose call sequences differ from each other at the positions of the branches and
* that contain iterated call sequences are created.(RQ-1.6)
*
* @param referenceUsageModelFileName
* file name of the reference model to store its result
* @param repositoryLookupModel
* repository lookup model
* @param correspondenceModel
* correspondence model
*
* @return a reference model and corresponding user sessions
* @throws IOException
* on error
*/
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, 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(3, 2);
final int numberOfConcurrentUsers = TestHelper.getRandomInteger(30, 10 * numberOfBranchTransitions);
final int lengthOfBranchSequence = TestHelper.getRandomInteger(2, 1);
final int countOfLoop = TestHelper.getRandomInteger(3, 2);
final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
final ReferenceElements referenceElements = new ReferenceElements();
// In the following the reference usage model is created
final UsageModel usageModel = UsageModelFactory.createUsageModel();
final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
// lastAction = start;
final Branch branch = LoopWithinBranchReference.createBranch(repositoryLookupModel, scenarioBehaviour, correspondenceModel, numberOfBranchTransitions, lengthOfBranchSequence, countOfLoop);
// 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. The
// branch transition counter ensures that each branch transition is represnted within the
// user sessions
final List<Integer> branchTransitionCounter = new ArrayList<>();
boolean areAllBranchesVisited = true;
do {
for (int i = 0; i < branch.getBranchTransitions_Branch().size(); i++) {
branchTransitionCounter.add(i, 0);
}
int entryTime = 1;
for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
entryTime = 1;
// Each user session represents one of the branch transitions
final int branchDecisioner = TestHelper.getRandomInteger(numberOfBranchTransitions - 1, 0);
if (branchDecisioner == 0) {
entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 0, 1, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
} else if (branchDecisioner == 1) {
entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 1, 2, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
} else if (branchDecisioner == 2) {
entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 2, 0, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
}
}
// It is checked whether all branch transitions are represented within the user sessions
for (int i = 0; i < branchTransitionCounter.size(); i++) {
if (branchTransitionCounter.get(i) == 0) {
areAllBranchesVisited = false;
break;
}
}
} while (!areAllBranchesVisited);
// Sets the likelihoods of the branch transitions according to the created user sessions
for (int i = 0; i < branch.getBranchTransitions_Branch().size(); i++) {
branch.getBranchTransitions_Branch().get(i).setBranchProbability((double) branchTransitionCounter.get(i) / (double) numberOfConcurrentUsers);
}
// 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.userbehavior.ReferenceElements in project iobserve-analysis by research-iobserve.
the class SimpleBranchReference method saveReferenceElements.
/**
* 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
*
* @param usageModel
* usage model
* @param referenceModelFileName
* reference model file name
* @param entryCallSequenceModel
* entry call sequence model
*
* @return reference elements
* @throws IOException
* when the file is written
*/
private static ReferenceElements saveReferenceElements(final UsageModel usageModel, final String referenceModelFileName, final EntryCallSequenceModel entryCallSequenceModel) throws IOException {
final ReferenceElements referenceElements = new ReferenceElements();
TestHelper.saveModel(usageModel, referenceModelFileName);
referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
referenceElements.setUsageModel(usageModel);
return referenceElements;
}
use of org.iobserve.analysis.userbehavior.ReferenceElements in project iobserve-analysis by research-iobserve.
the class BranchWithinLoopReference method getModel.
/**
* It creates a reference usage model that contains branches within loops. Accordingly, user
* sessions whose call sequences differ from each other are iterated in a row. Thereby, at each
* iteration of a branched call sequences the probabilities have to be equal because otherwise
* it would not be an iteration (RQ-1.8)
*
* @param referenceUsageModelFileName
* reference usage model file name
* @param repositoryLookupModel
* repository model builder
* @param correspondenceModel
* correspondence model
*
* @return reference usage model and corresponding user sessions
* @throws IOException
* on error
*/
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel) throws IOException {
// The number of model element parameters are created randomly. The number of user sessions
// must be created accordingly to the number of branch transitions, because it must be
// ensured that at each iteration of an branch the branch transition probabilities are
// equal. This can be achieved by the same number of user sessions representing the branch
// transition at each iteration
final int numberOfLoops = TestHelper.getRandomInteger(3, 3);
final int numberOfConcurrentUsers = (int) Math.pow(2, numberOfLoops) * 5;
final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
final ReferenceElements testElements = new ReferenceElements();
// In the following the reference usage model is created
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);
final AbstractUserAction lastAction = start;
// The loop element is created that contains the iterated branch
final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
final ScenarioBehaviour loopScenarioBehaviour = loop.getBodyBehaviour_Loop();
UsageModelFactory.connect(lastAction, loop);
final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmLoopIteration.setSpecification(String.valueOf(numberOfLoops));
// Set number of loops
loop.setLoopIteration_Loop(pcmLoopIteration);
UsageModelFactory.connect(loop, stop);
final Start loopStart = UsageModelFactory.createAddStartAction("", loopScenarioBehaviour);
final Stop loopStop = UsageModelFactory.createAddStopAction("", loopScenarioBehaviour);
// The branch that is contained within the loop element is created
final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", loopScenarioBehaviour);
UsageModelFactory.connect(loopStart, branch);
// The branch transition 1 is created
final BranchTransition branchTransition1 = BranchWithinLoopReference.createBranchTransition(2, repositoryLookupModel, branch, correspondenceModel);
// The branch transition 2 is created
final BranchTransition branchTransition2 = BranchWithinLoopReference.createBranchTransition(3, repositoryLookupModel, branch, correspondenceModel);
final Optional<Correspondent> optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4]);
if (optionCorrespondent.isPresent()) {
final Correspondent correspondent = optionCorrespondent.get();
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
UsageModelFactory.addUserAction(loopScenarioBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(branch, entryLevelSystemCall);
UsageModelFactory.connect(entryLevelSystemCall, loopStop);
}
// User sessions according to the reference usage model are created. Thereby, it must be
// ensured that each iteration of the branch the branch probabilities stay the same because
// the branch is iterated. This can be achieved by an equal number of user sessions for each
// branch transition at each iteration of the branch
int countOfCallEvent3 = 0;
int countOfCallEvent4 = 0;
int entryTime = 1;
int exitTime = 2;
boolean branchDecision = false;
// At each iteration the user sessions are distributed equally between the branch
// transitions to ensure that the probabilities of the branch transitions stay equally
final Map<Integer, List<List<UserSession>>> userSessionGroups = new HashMap<>();
final List<List<UserSession>> startList = new ArrayList<>();
startList.add(entryCallSequenceModel.getUserSessions());
userSessionGroups.put(0, startList);
// The loop that contains the branch
for (int j = 0; j < numberOfLoops; j++) {
countOfCallEvent3 = 0;
countOfCallEvent4 = 0;
final List<List<UserSession>> newUserSessionGroups = new ArrayList<>();
// Ensures that the user sessions distribution stays equally
for (int k = 0; k < userSessionGroups.get(j).size(); k++) {
for (int i = 0; i < 2; i++) {
final List<UserSession> userSessions = new ArrayList<>();
newUserSessionGroups.add(userSessions);
}
final int indexGroupCallEvent3 = newUserSessionGroups.size() - 2;
final int indexGroupCallEvent4 = newUserSessionGroups.size() - 1;
for (int i = 0; i < userSessionGroups.get(j).get(k).size(); i++) {
if (newUserSessionGroups.get(indexGroupCallEvent3).size() > newUserSessionGroups.get(indexGroupCallEvent4).size()) {
branchDecision = false;
} else {
branchDecision = true;
}
// The branch within the loop
if (branchDecision) {
BranchWithinLoopReference.createEntryCall(entryTime, exitTime, 2, k, j, i, userSessionGroups, newUserSessionGroups, indexGroupCallEvent3);
countOfCallEvent3++;
entryTime += 2;
exitTime += 2;
} else {
BranchWithinLoopReference.createEntryCall(entryTime, exitTime, 3, k, j, i, userSessionGroups, newUserSessionGroups, indexGroupCallEvent4);
countOfCallEvent4++;
entryTime += 2;
exitTime += 2;
}
final EntryCallEvent entryCallEvent5 = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4], ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], String.valueOf(i), "hostname");
userSessionGroups.get(j).get(k).get(i).add(entryCallEvent5, true);
entryTime -= 2;
exitTime -= 2;
}
}
userSessionGroups.put(j + 1, newUserSessionGroups);
entryTime += 2;
exitTime += 2;
}
// Sets the likelihoods of branch transitions
final double likelihoodOfCallEvent3 = (double) countOfCallEvent3 / (double) numberOfConcurrentUsers;
final double likelihoodOfCallEvent4 = (double) countOfCallEvent4 / (double) numberOfConcurrentUsers;
branchTransition1.setBranchProbability(likelihoodOfCallEvent3);
branchTransition2.setBranchProbability(likelihoodOfCallEvent4);
// 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);
testElements.setEntryCallSequenceModel(entryCallSequenceModel);
testElements.setUsageModel(usageModel);
return testElements;
}
Aggregations