use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.
the class UserBehaviorEvaluation method matchUsageModels.
/**
* Executes the matching of the two passed usage models.
*
* @param createdUsageModel
* is matched against the reference usage model
* @param referenceUsageModel
* is matched against the approach's generated usage model
* @return returns accuracy results
* @throws IOException
* on error
*/
public static AccuracyResults matchUsageModels(final UsageModel createdUsageModel, final UsageModel referenceUsageModel) throws IOException {
final AccuracyResults accuracyResults = new AccuracyResults();
// Get the scenario behavior of each usage model
final UsageScenario usageScenarioOfCreatedUsageModel = createdUsageModel.getUsageScenario_UsageModel().get(0);
final UsageScenario usageScenarioOfReferenceUsageModel = referenceUsageModel.getUsageScenario_UsageModel().get(0);
final ScenarioBehaviour scenarioBehaviourOfCreatedUsageModel = usageScenarioOfCreatedUsageModel.getScenarioBehaviour_UsageScenario();
final ScenarioBehaviour scenarioBehaviourOfReferenceUsageModel = usageScenarioOfReferenceUsageModel.getScenarioBehaviour_UsageScenario();
// Creates for each usage model a list that contains the usage model's model elements
final List<ModelElement> modelElementsOfCreatedUsageModel = new ArrayList<>();
final List<ModelElement> modelElementsOfReferenceUsageModel = new ArrayList<>();
UserBehaviorEvaluation.getModelElements(scenarioBehaviourOfCreatedUsageModel, modelElementsOfCreatedUsageModel);
UserBehaviorEvaluation.getModelElements(scenarioBehaviourOfReferenceUsageModel, modelElementsOfReferenceUsageModel);
// Calculate the evaluation metrics according to the extracted lists of model elements
final double jc = UserBehaviorEvaluation.calculateJC(modelElementsOfCreatedUsageModel, modelElementsOfReferenceUsageModel);
final double srcc = UserBehaviorEvaluation.calculateSpearmansCoefficient(modelElementsOfCreatedUsageModel, modelElementsOfReferenceUsageModel);
accuracyResults.setJc(jc);
accuracyResults.setSrcc(srcc);
return accuracyResults;
}
use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.
the class UsageModelProviderTest method createThenReadById.
@Override
@Test
public void createThenReadById() {
final ModelProvider<UsageModel> modelProvider = new ModelProvider<>(UsageModelProviderTest.graph);
final ModelProvider<UsageScenario> modelProvider2 = new ModelProvider<>(UsageModelProviderTest.graph);
final UsageModel writtenModel = new TestModelBuilder().getUsageModel();
final UsageScenario writtenScenario = writtenModel.getUsageScenario_UsageModel().get(0);
final UsageScenario readScenario;
// Create complete model but only read a UsageScenario, because UsageModel itself has no id
modelProvider.createComponent(writtenModel);
readScenario = modelProvider2.readOnlyComponentById(UsageScenario.class, writtenScenario.getId());
Assert.assertTrue(this.equalityHelper.equals(writtenScenario, readScenario));
}
use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.
the class UsageModelProviderTest method createThenReadReferencing.
@Override
@Test
public void createThenReadReferencing() {
final ModelProvider<UsageModel> modelProvider = new ModelProvider<>(UsageModelProviderTest.graph);
final TestModelBuilder testModelBuilder = new TestModelBuilder();
final UsageModel writtenModel = testModelBuilder.getUsageModel();
final UsageScenario writtenScenario = writtenModel.getUsageScenario_UsageModel().get(0);
final List<EObject> readReferencingComponents;
modelProvider.createComponent(writtenModel);
// Using usage scenario because usage model does not have an id
readReferencingComponents = modelProvider.readOnlyReferencingComponentsById(UsageScenario.class, writtenScenario.getId());
// Only the scenario behavior and the closed workload reference the usage scenario
for (final EObject readReferencingComponent : readReferencingComponents) {
Assert.assertTrue(this.equalityHelper.equals(testModelBuilder.getBuyBookScenarioBehaviour(), readReferencingComponent) || this.equalityHelper.equals(testModelBuilder.getClosedWorkload(), readReferencingComponent));
}
}
use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.
the class UsageModelProviderTest method createThenReadByType.
@Override
@Test
public void createThenReadByType() {
final ModelProvider<UsageModel> modelProvider = new ModelProvider<>(UsageModelProviderTest.graph);
final ModelProvider<UsageScenario> modelProvider2 = new ModelProvider<>(UsageModelProviderTest.graph);
final UsageModel writtenModel = new TestModelBuilder().getUsageModel();
final UsageScenario writtenScenario = writtenModel.getUsageScenario_UsageModel().get(0);
final List<String> readIds;
// Create complete model but only read a UsageScenario, because UsageModel itself has no id
modelProvider.createComponent(writtenModel);
readIds = modelProvider2.readComponentByType(UsageScenario.class);
// There is only one usage scenario in the test model
Assert.assertTrue(readIds.size() == 1);
Assert.assertTrue(writtenScenario.getId().equals(readIds.get(0)));
}
use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.
the class BranchWithinBranchReference method createTheReferenceModel.
/**
* Creates the reference model.
*
* @param usageModelBuilder
* @param repositoryLookupModel
* @param correspondenceModel
* @param numberOfTransitionsOfExteriorBranch
* @param numberOfTransitionsOfInteriorBranches
* @param numberOfConcurrentUsers
* @param branchTransitionCounter
* @param listOfbranchTransitionCounterInterior
* @return
*/
private static UsageModel createTheReferenceModel(final UsageModelFactory usageModelBuilder, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel, final int numberOfTransitionsOfExteriorBranch, final int numberOfTransitionsOfInteriorBranches, final int numberOfConcurrentUsers, final List<Integer> branchTransitionCounter, final List<List<Integer>> listOfbranchTransitionCounterInterior) {
// In the following the reference usage model is created
AbstractUserAction lastAction;
Optional<Correspondent> optionCorrespondent;
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);
lastAction = start;
// The exterior branch is created
final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", scenarioBehaviour);
UsageModelFactory.connect(lastAction, branch);
UsageModelFactory.connect(branch, stop);
// Creates branch transitions according to the random countOfBranchTransitions
for (int i = 0; i < numberOfTransitionsOfExteriorBranch; i++) {
final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branch);
final ScenarioBehaviour branchTransitionBehaviour = branchTransition.getBranchedBehaviour_BranchTransition();
branchTransition.setBranchProbability((double) branchTransitionCounter.get(i) / (double) numberOfConcurrentUsers);
final Start startBranchTransition = UsageModelFactory.createStart("");
UsageModelFactory.addUserAction(branchTransitionBehaviour, startBranchTransition);
final Stop stopBranchTransition = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(branchTransitionBehaviour, stopBranchTransition);
lastAction = startBranchTransition;
if (i >= 0 && i < 3) {
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 EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, optionCorrespondent.get());
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
// The interior branch is created
final org.palladiosimulator.pcm.usagemodel.Branch branchInterior = UsageModelFactory.createBranch("", branchTransitionBehaviour);
UsageModelFactory.connect(lastAction, branchInterior);
UsageModelFactory.connect(branchInterior, stopBranchTransition);
for (int j = 0; j < numberOfTransitionsOfInteriorBranches; j++) {
final BranchTransition branchTransitionInterior = UsageModelFactory.createBranchTransition(branchInterior);
final ScenarioBehaviour branchTransitionBehaviourInterior = branchTransitionInterior.getBranchedBehaviour_BranchTransition();
branchTransitionInterior.setBranchProbability((double) listOfbranchTransitionCounterInterior.get(i).get(j) / (double) branchTransitionCounter.get(i));
final Start startBranchTransitionInterior = UsageModelFactory.createAddStartAction("", branchTransitionBehaviourInterior);
final Stop stopBranchTransitionInterior = UsageModelFactory.createAddStopAction("", branchTransitionBehaviourInterior);
lastAction = startBranchTransitionInterior;
optionCorrespondent = BranchWithinBranchReference.getOptionCorrespondent(correspondenceModel, j);
if (optionCorrespondent.isPresent()) {
final Correspondent correspondent = optionCorrespondent.get();
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
UsageModelFactory.addUserAction(branchTransitionBehaviourInterior, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, stopBranchTransitionInterior);
}
}
return usageModel;
}
Aggregations