Skip to content

Instantly share code, notes, and snippets.

@Mackaber
Created November 28, 2018 18:00
Show Gist options
  • Save Mackaber/1a3846fb4c2ad17c9985d87e4e303ee7 to your computer and use it in GitHub Desktop.
Save Mackaber/1a3846fb4c2ad17c9985d87e4e303ee7 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"%classpath add jar ../jMetal/out/artifacts/Tesis_jar/Tesis.jar\n\npackage me.mackaber.tesis.MultiObjective;\n\nimport me.mackaber.tesis.ObjectiveFunctions.GroupSizeFunction;\nimport me.mackaber.tesis.ObjectiveFunctions.InterestsCosineSimilarityFunction;\nimport me.mackaber.tesis.ObjectiveFunctions.LevelFunction;\nimport me.mackaber.tesis.ObjectiveFunctions.ParticipationStyleFunction;\nimport me.mackaber.tesis.SingleObjective.GroupingSolution;\nimport me.mackaber.tesis.Util.GroupSwapMutation;\nimport me.mackaber.tesis.Util.User;\nimport org.apache.commons.math3.stat.descriptive.moment.GeometricMean;\nimport org.uma.jmetal.algorithm.Algorithm;\nimport org.uma.jmetal.algorithm.multiobjective.nsgaii.NSGAIIBuilder;\nimport org.uma.jmetal.operator.MutationOperator;\nimport org.uma.jmetal.operator.SelectionOperator;\nimport org.uma.jmetal.operator.impl.crossover.NPointCrossover;\nimport org.uma.jmetal.operator.impl.selection.BinaryTournamentSelection;\nimport org.uma.jmetal.util.AlgorithmRunner;\nimport org.uma.jmetal.util.JMetalLogger;\nimport org.uma.jmetal.util.comparator.RankingAndCrowdingDistanceComparator;\nimport org.uma.jmetal.util.fileoutput.SolutionListOutput;\nimport org.uma.jmetal.util.fileoutput.impl.DefaultFileOutputContext;\nimport org.uma.jmetal.util.pseudorandom.JMetalRandom;\n\nJMetalRandom.getInstance().setSeed(100L);\n\nproblem = new MultiObjectiveGrouping(\"../Resources/synthetic.csv\");\n\nproblem.setGroupSizeRange(3, 6)\n .addObjectiveFunction(new GroupSizeFunction())\n .addObjectiveFunction(new LevelFunction())\n .addObjectiveFunction(new ParticipationStyleFunction())\n .setInterestsFunction(new InterestsCosineSimilarityFunction(\"../Resources/custom_interests.json\"))\n .setCentralTendencyMeasure(new GeometricMean())\n .build();\n\ncrossover = new NPointCrossover(0.02,3333);\nmutation = new GroupSwapMutation<>(0.02, problem);\nselection = new BinaryTournamentSelection<>(new RankingAndCrowdingDistanceComparator<>());\nalgorithm = new NSGAIIBuilder<>(problem, crossover, mutation)\n .setSelectionOperator(selection)\n .setMaxEvaluations(10)\n .setPopulationSize(10)\n .build();\n\nalgorithmRunner = new AlgorithmRunner.Executor(algorithm).execute();\n\npopulation = algorithm.getResult();\ncomputingTime = algorithmRunner.getComputingTime();\n\nnew SolutionListOutput(population)\n .setSeparator(\"\\t\")\n .setVarFileOutputContext(new DefaultFileOutputContext(\"VAR.tsv\"))\n .setFunFileOutputContext(new DefaultFileOutputContext(\"FUN.tsv\"))\n .print();\n\nJMetalLogger.logger.info(\"Total execution time: \" + computingTime + \"ms\");\nJMetalLogger.logger.info(\"Random seed: \" + JMetalRandom.getInstance().getSeed());\nJMetalLogger.logger.info(\"Objectives values have been written to file FUN.tsv\");\nJMetalLogger.logger.info(\"Variables values have been written to file VAR.tsv\");","execution_count":4,"outputs":[{"output_type":"stream","text":"2018-11-28 11:30:33.862 INFO: Total execution time: 3909ms [java_util_logging_Logger$info call]\n2018-11-28 11:30:33.868 INFO: Random seed: 100 [java_util_logging_Logger$info call]\n2018-11-28 11:30:33.869 INFO: Objectives values have been written to file FUN.tsv [java_util_logging_Logger$info call]\n2018-11-28 11:30:33.872 INFO: Variables values have been written to file VAR.tsv [java_util_logging_Logger$info call]\n","name":"stderr"},{"output_type":"execute_result","execution_count":4,"data":{"text/plain":"null"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"population.get(2).getSampleSolution(2)","execution_count":9,"outputs":[{"output_type":"display_data","data":{"method":"display_data","application/vnd.jupyter.widget-view+json":{"version_minor":0,"model_id":"2b0e2475-3d9a-4959-a628-7934ac2a70b6","version_major":2}},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"plot = new Plot(title: \"Pareto Front\", initHeight: 200)\n\nresults = []\n\nfor(int i = 0; i<10;i++) {\n problem.evaluate(solution);\n results << solution.getObjective(0);\n newSolution = localSearch.execute(solution); \n}\n\nplot << new Line(y: results, width: 1, color: Color.green)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"groovy","display_name":"Groovy","language":"groovy"},"toc":{"nav_menu":{},"number_sections":false,"sideBar":false,"skip_h1_title":false,"base_numbering":1,"title_cell":"Table of Contents","title_sidebar":"Contents","toc_cell":false,"toc_position":{},"toc_section_display":false,"toc_window_display":false},"language_info":{"nbconverter_exporter":"","codemirror_mode":"groovy","name":"Groovy","mimetype":"","file_extension":".groovy","version":"2.4.3"}},"nbformat":4,"nbformat_minor":2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment