1 #include <shark/Algorithms/DirectSearch/Indicators/AdditiveEpsilonIndicator.h> 2 #include <shark/Algorithms/DirectSearch/FitnessExtractor.h> 3 #include <shark/Algorithms/DirectSearch/ParetoDominanceComparator.h> 4 #include <shark/Algorithms/DirectSearch/FastNonDominatedSort.h> 6 #include <boost/program_options.hpp> 7 #include <boost/algorithm/string.hpp> 16 template<
typename Stream>
17 FrontType
read_front( Stream & in, std::size_t noObjectives,
const std::string & separator =
" ", std::size_t headerLines = 0 ) {
20 throw(
shark::Exception(
"Bad stream in shark::read_front", __FILE__, __LINE__ ) );
26 std::size_t counter = 0;
27 for( counter = 0; counter < headerLines; counter++ )
28 std::getline( in, line );
32 while( std::getline( in, line ) ) {
36 std::vector< std::string > tokens;
37 boost::algorithm::split( tokens, line, boost::is_any_of( separator ), boost::token_compress_on );
39 if( tokens.size() < noObjectives )
42 shark::RealVector v( noObjectives, 0. );
44 for( std::size_t i = 0; i < noObjectives; i++ ) {
45 v[ i ] = boost::lexical_cast<
double>( tokens[ i ] );
49 result.push_back( v );
56 int main(
int argc,
char ** argv ) {
58 boost::program_options::options_description options;
60 (
"referenceFront", boost::program_options::value< std::string >(),
"File containing the reference front" )
61 (
"noObjectives", boost::program_options::value< std::size_t >(),
"No of objectives" )
62 (
"separator", boost::program_options::value< std::string >()->default_value(
" " ),
"Character that separates fields" )
63 (
"headerLines", boost::program_options::value< std::size_t >()->default_value( 0 ),
"Amount of header lines to skip" );
66 boost::program_options::variables_map vm;
68 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, options), vm);
69 boost::program_options::notify(vm);
71 std::cerr << options << std::endl;
72 return( EXIT_FAILURE );
75 if( vm.count(
"referenceFront" ) == 0 ) {
76 std::cerr << options << std::endl;
77 return( EXIT_FAILURE );
80 if( vm.count(
"noObjectives" ) == 0 ) {
81 std::cerr << options << std::endl;
82 return( EXIT_FAILURE );
85 std::size_t noObjectives = vm[
"noObjectives" ].as< std::size_t >();
86 std::string referenceFront = vm[
"referenceFront" ].as< std::string >();
88 std::ifstream in( referenceFront.c_str() );
93 refFront =
shark::read_front( in, noObjectives, vm[
"separator" ].as< std::string >() );
95 std::cerr <<
"Problem reading reference front, aborting now." << std::endl;
96 std::cerr << exp.
what() << std::endl;
97 return( EXIT_FAILURE );
103 front =
shark::read_front( std::cin, noObjectives, vm[
"separator" ].as< std::string >(), vm[
"headerLines" ].as< std::size_t >() );
105 std::cerr <<
"Problem reading front from std::cin, aborting now." << std::endl;
106 return( EXIT_FAILURE );
111 shark::IdentityFitnessExtractor ife;
113 std::cout << addEps( front.begin(),front.end(), refFront.begin(),refFront.end(), ife ) << std::endl;
115 return( EXIT_SUCCESS );