iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.SetContribution.java Source code

Java tutorial

Introduction

Here is the source code for iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.SetContribution.java

Source

/* Copyright 2009-2015 David Hadka
 *
 * This file is part of the MOEA Framework.
 *
 * The MOEA Framework is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * The MOEA Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with the MOEA Framework.  If not, see <http://www.gnu.org/licenses/>.
 */
package iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity;

import java.io.File;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import iDynoOptimizer.MOEAFramework26.src.org.moeaframework.core.NondominatedPopulation;
import iDynoOptimizer.MOEAFramework26.src.org.moeaframework.core.PopulationIO;
import iDynoOptimizer.MOEAFramework26.src.org.moeaframework.core.indicator.Contribution;
import iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.CommandLineUtility;
import iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.TypedProperties;

/**
 * Command line utility for reporting the number of solutions in a set that are
 * contained within a reference set.  The common use-case of this utility is to
 * determine the percent makeup of the individual approximation sets used 
 * during the reference set construction.
 */
public class SetContribution extends CommandLineUtility {

    /**
     * Constructs the command line utility for reporting the number of
     * solutions in a set that are contained within a reference set.
     */
    public SetContribution() {
        super();
    }

    @SuppressWarnings("static-access")
    @Override
    public Options getOptions() {
        Options options = super.getOptions();

        options.addOption(
                OptionBuilder.withLongOpt("reference").hasArg().withArgName("file").isRequired().create('r'));
        options.addOption(OptionBuilder.withLongOpt("epsilon").hasArg().withArgName("e1,e2,...").create('e'));

        return options;
    }

    @Override
    public void run(CommandLine commandLine) throws Exception {
        NondominatedPopulation referenceSet = new NondominatedPopulation(
                PopulationIO.readObjectives(new File(commandLine.getOptionValue("reference"))));
        Contribution contribution = null;

        if (commandLine.hasOption("epsilon")) {
            double[] epsilon = TypedProperties.withProperty("epsilon", commandLine.getOptionValue("epsilon"))
                    .getDoubleArray("epsilon", null);
            contribution = new Contribution(referenceSet, epsilon);
        } else {
            contribution = new Contribution(referenceSet);
        }

        for (String filename : commandLine.getArgs()) {
            NondominatedPopulation approximationSet = new NondominatedPopulation(
                    PopulationIO.readObjectives(new File(filename)));

            System.out.print(filename);
            System.out.print(' ');
            System.out.println(contribution.evaluate(approximationSet));
        }
    }

    /**
     * Starts the command line utility for reporting the number of solutions in
     * a set that are contained within a reference set.
     * 
     * @param args the command line arguments
     * @throws Exception if an error occurred
     */
    public static void main(String[] args) throws Exception {
        new SetContribution().start(args);
    }

}