Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Quality indicators #5

Merged
merged 7 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.uma.jmetal.util.archive.impl.NonDominatedSolutionListArchive;
import org.uma.jmetal.util.fileoutput.SolutionListOutput;
import org.uma.jmetal.util.front.Front;
import org.uma.jmetal.util.front.imp.ArrayFront;
import org.uma.jmetal.util.front.util.FrontUtils;
import org.uma.jmetal.util.point.util.PointSolution;
import org.uma.jmetal.util.solutionattribute.impl.GenericSolutionAttribute;

import it.univaq.disim.sealab.metaheuristic.evolutionary.Controller;
import it.univaq.disim.sealab.metaheuristic.utils.FileUtils;

public class Launcher {

Expand Down Expand Up @@ -45,13 +57,32 @@ public static void singleModel(String configFile) {
}

public static void runExperiment(String configFile) {
new Controller(configFile).runExperiment();
Controller ctr = new Controller(configFile);
ctr.runExperiment();
ctr.generateAvailability();
}

public static void availability(final String twoTowersKernelPath, final String targetFolder) {
File avaFolder = Paths.get(targetFolder, "availability").toFile();
//avaFolder.mkdirs();
new Controller().generateAvailability(twoTowersKernelPath, new File(targetFolder), avaFolder);
}

public static void main(String[] args) {
List<String> argsList = Arrays.asList(args);
Controller.setSOR(argsList.contains("-sor"));

if (argsList.contains("-sP")) {
try {
final String rPF = "/Users/peo12/git/sealab/easier/easier-dataAnalyst/data/P_64_E_4480_X_0.8_M_0.2/referenceFront/P_64_E_4480_X_0.8_M_0.2";
final String sPF_folder = "/Users/peo12/git/sealab/easier/easier-dataAnalyst/data/superpareto";
generateReferenceParetoFront(rPF, sPF_folder);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if (argsList.contains("-m")) {
multiModels(argsList.get(argsList.indexOf("-m") + 1));
}
Expand All @@ -60,9 +91,66 @@ public static void main(String[] args) {
singleModel((argsList.get(argsList.indexOf("-s") + 1)));
}

//Runs experiment
if (argsList.contains("-sE")) {
runExperiment((argsList.get(argsList.indexOf("-sE") + 1)));
}

String twoTowersKernelPath = "";

//uses a new TTKernel path
if (argsList.contains("-t")) {
twoTowersKernelPath = argsList.get(argsList.indexOf("-t") + 1);
}

if (argsList.contains("-ava")) {
availability(twoTowersKernelPath, (argsList.get(argsList.indexOf("-ava") + 1)));
}
}

public static void generateReferenceParetoFront(final String rPFile, final String sPF) throws Exception {

// File referencePareto = new File(rPFile);

File sPF_folder = new File(sPF);

NonDominatedSolutionListArchive<PointSolution> nonDominatedSolutionArchive = new NonDominatedSolutionListArchive<PointSolution>();

Set<File> solutions = FileUtils.listFilesRecursively(sPF_folder);

// good way:
Iterator<File> iterator = solutions.iterator();
while (iterator.hasNext()) {
File setElement = iterator.next();
Front front = new ArrayFront(setElement.getPath());
List<PointSolution> solutionList = FrontUtils.convertFrontToSolutionList(front);
// GenericSolutionAttribute<PointSolution, String> solutionAttribute = new
// GenericSolutionAttribute<PointSolution, String>();
for (PointSolution solution : solutionList) {
// solutionAttribute.setAttribute(solution, algorithm.getAlgorithmTag());
nonDominatedSolutionArchive.add(solution);
}
}

String referenceSetFileName = rPFile + ".rf";

new SolutionListOutput(nonDominatedSolutionArchive.getSolutionList())
.printObjectivesToFile(referenceSetFileName);

// for (int i = 0; i < num_of_solutions; i++) {
// String frontFileName = problemDirectory + "/" +
// experiment.getOutputParetoFrontFileName() + i + ".tsv";
// Front front = new ArrayFront(frontFileName);
// List<PointSolution> solutionList =
// FrontUtils.convertFrontToSolutionList(front);
// GenericSolutionAttribute<PointSolution, String> solutionAttribute = new
// GenericSolutionAttribute<PointSolution, String>();
//
// for (PointSolution solution : solutionList) {
// solutionAttribute.setAttribute(solution, algorithm.getAlgorithmTag());
// nonDominatedSolutionArchive.add(solution);
// }
// }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class AemiliaAvailabilityManager {
public AemiliaAvailabilityManager(Controller ctrl) {
controller = ctrl;
manager = controller.getManager();
packageRegistering();
}

public void packageRegistering() {
Expand All @@ -79,6 +80,8 @@ public void doAvailability() {
Resource targetResource = manager.getMetamodelManager().getResourceSet()
.getResource(manager.string2FileUri(modelFile.getAbsolutePath()), true);
addAvailability((AEmiliaSpecification) targetResource.getContents().get(0));
writeAvaRewFile((AEmiliaSpecification) targetResource.getContents().get(0),
modelFile.getParentFile().toPath());
try {
targetResource.save(null);
} catch (IOException e) {
Expand Down Expand Up @@ -149,44 +152,59 @@ public static Set<File> listFilesRecursively(final File folder) {

private void addAvailability(AEmiliaSpecification targetModel) {

Properties prop = new Properties();
try {
prop.load(new FileInputStream(controller.getFailureRatesPropertiesFile()));
} catch (IOException e) {
e.printStackTrace();
}

for (ElemType elemType : targetModel.getArchiTypeDecl().getAetDeclaration().getEtDeclaration()) {
OutputInteraction failOutputInteraction = createOutputInteraction(elemType, "fail_" + elemType.getEtName(),
targetModel);
if (prop.getProperty(elemType.getEtName()) != null) {
OutputInteraction failOutputInteraction = createOutputInteraction(elemType,
"fail_" + elemType.getEtName(), targetModel);

ConstInit constWeight = setConstWeight(elemType);
ConstInit constWeight = setConstWeight(elemType);

targetModel.getArchiTypeDecl().getHeader().getInitConst().add(constWeight);
elemType.getElemHeader().getCostant().add(createConst(constWeight));
targetModel.getArchiTypeDecl().getHeader().getInitConst().add(constWeight);
elemType.getElemHeader().getCostant().add(createConst(constWeight));

updateArchiElemInstanceParameters(elemType, targetModel, constWeight);
updateArchiElemInstanceParameters(elemType, targetModel, constWeight);

for (BehavEquation behEq : elemType.getBehaviorDecl().getEquations()) {
ChoiceProcess availabilityChoice = behaviourFactory.createChoiceProcess();
ActionProcess failProcess = createFailBranchProcess(elemType, failOutputInteraction, behEq,
constWeight);
ActionProcess goodProcess = createGoodBranchProcess(elemType, behEq, constWeight);
availabilityChoice.getProcesses().add(failProcess);
availabilityChoice.getProcesses().add(goodProcess);
behEq.setPt(availabilityChoice);
for (BehavEquation behEq : elemType.getBehaviorDecl().getEquations()) {
ChoiceProcess availabilityChoice = behaviourFactory.createChoiceProcess();
ActionProcess failProcess = createFailBranchProcess(elemType, failOutputInteraction, behEq,
constWeight);
ActionProcess goodProcess = createGoodBranchProcess(elemType, behEq, constWeight);
availabilityChoice.getProcesses().add(failProcess);
availabilityChoice.getProcesses().add(goodProcess);
behEq.setPt(availabilityChoice);
}
}
}
}

private void writeAvaRewFile(final AEmiliaSpecification targetModel, final Path folderPath) {

Properties prop = new Properties();
try {
prop.load(new FileInputStream(controller.getFailureRatesPropertiesFile()));
} catch (IOException e) {
e.printStackTrace();
}
try (BufferedWriter bw = new BufferedWriter(
new FileWriter(Paths.get(folderPath.toString(), "ava.rew").toFile()))) {
bw.write("MEASURE Lose IS \n");
for (ArchiElemInstance elemInstance : targetModel.getArchiTypeDecl().getAtDeclaration().getAeiDecl()) {
bw.write(String.format("\t ENABLED (%s.fail_%s) -> STATE_REWARD(1.0)\n", elemInstance.getInstanceName(),
if (prop.getProperty(elemInstance.getTypeOf().getEtName()) != null)
bw.write(String.format("\t ENABLED (%s.fail_%s) -> STATE_REWARD(1.0)\n", elemInstance.getInstanceName(),
elemInstance.getTypeOf().getEtName()));
}
} catch (IOException e) {
e.printStackTrace();
}

}


private void updateArchiElemInstanceParameters(ElemType e, AEmiliaSpecification targetModel, ConstInit cWeight) {
for (ArchiElemInstance aei : targetModel.getArchiTypeDecl().getAtDeclaration().getAeiDecl()) {
if (aei.getTypeOf().getEtName().equals(e.getEtName())) {
Expand Down
Loading