Commit Graph

211 Commits

Author SHA1 Message Date
Kamil Śliwak
8b443627e2 [yul-phaser] Add ProgramCache class 2020-03-24 17:39:24 +01:00
chriseth
f89e154693
Merge pull request #8514 from imapp-pl/yul-phaser-prefix-option
[yul-phaser] --prefix option
2020-03-24 17:35:45 +01:00
Kamil Śliwak
a66ceb11c6 [yul-phaser] Add --prefix option 2020-03-23 16:31:35 +01:00
Kamil Śliwak
29186f9951 [yul-phaser] Program: Switch from using parseCode() to parseObject() 2020-03-23 16:31:19 +01:00
Kamil Śliwak
7107ef13a7 [yul-phaser] Program: Add parseObject() 2020-03-23 16:31:19 +01:00
Kamil Śliwak
905147321b [yul-phaser] Phaser: Change default metric to RelativeCodeSize 2020-03-18 16:28:16 +01:00
Kamil Śliwak
d86652cb96 [yul-phaser] Add --metric-aggregator option 2020-03-18 16:28:16 +01:00
Kamil Śliwak
bc46323bed [yul-phaser] Phaser: Accepting multiple input programs
- Use average of metric values for individual programs as the overall metric.
2020-03-18 16:28:16 +01:00
Kamil Śliwak
01050940fd [yul-phaser] Add --relative-metric-scale option 2020-03-18 16:28:16 +01:00
Kamil Śliwak
8e64c5c6f0 [yul-phaser] Add --metric option 2020-03-18 16:28:16 +01:00
Kamil Śliwak
e4a360947b [yul-phaser] Add FitnessMetricCombination and derived classes for average, sum, min and max 2020-03-18 16:28:16 +01:00
Kamil Śliwak
0e03839e62 [yul-phaser] Add RelativeProgramSize metric 2020-03-18 16:28:15 +01:00
Kamil Śliwak
7edbbe4edd [yul-phaser] Make FitnessMetric::evaluate() non-const 2020-03-18 16:28:15 +01:00
Kamil Śliwak
0913fd1aac [yul-phaser] Extract ProgramBasedMetric base class from ProgramSize 2020-03-18 16:28:15 +01:00
Kamil Śliwak
7a1f6a27db [yul-phaser] More data accessors in metric and algorithm classes 2020-03-18 13:30:58 +01:00
Kamil Śliwak
2563e7a7e3 [yul-phaser] Add --no-randomise-duplicates option 2020-03-18 13:30:58 +01:00
Kamil Śliwak
18f0d6eb94 [yul-phaser] AlgorithmRunner: Duplicate chromosome randomisation 2020-03-18 13:30:58 +01:00
Kamil Śliwak
b11eff7c88 [yul-phaser] Add options for all algorithm-specific parameters 2020-03-18 13:30:58 +01:00
Kamil Śliwak
55ea92dbec [yul-phaser] Add --min-chromosome-length and --max-chromosome-length options 2020-03-18 13:30:58 +01:00
Kamil Śliwak
3f7ada1689 [yul-phaser] Add --population-autosave option 2020-03-18 13:30:58 +01:00
Kamil Śliwak
1b5960111d [yul-phaser] AlgorithmRunner: Population autosave 2020-03-18 13:30:58 +01:00
Kamil Śliwak
04c7c56d84 [yul-phaser] Add --population-from-file option 2020-03-18 13:30:58 +01:00
Kamil Śliwak
ff99d25bc3 [yul-phaser] Common: Add readLinesFromFile() 2020-03-18 13:30:58 +01:00
Kamil Śliwak
5e00b57e02 [yul-phaser] Add --population option 2020-03-18 13:30:58 +01:00
Kamil Śliwak
af090876b5 [yul-phaser] Add --random-population option 2020-03-18 13:30:58 +01:00
Kamil Śliwak
d8e5f8f965 [yul-phaser] Add --rounds option 2020-03-18 13:30:58 +01:00
Kamil Śliwak
63f13c5b18 [yul-phaser] Add --chromosome-repetitions option 2020-03-18 13:30:58 +01:00
Kamil Śliwak
760e7c3cc5 [yul-phaser] Don't return exit code from Phaser::main() and just assume 0 if it does not throw. 2020-03-16 20:32:59 +01:00
Kamil Śliwak
d86b5019dc [yul-phaser] Phaser: Returning exit code 0 instead of 2 when --help is requested
- I don't think we really need to discern it from normal operation. It's what user requested so it's a success.
2020-03-16 20:32:59 +01:00
Kamil Śliwak
f05a07d0cc [yul-phaser] Create BadInput exception hierarchy and make exceptions used by Phaser more specific 2020-03-16 20:32:59 +01:00
Kamil Śliwak
53803801f7 [yul-phaser] Move handling of boost::program_options::error to the top-level exception handler 2020-03-16 20:32:59 +01:00
Kamil Śliwak
4e90c598b3 [yul-phaser] main: Dealing with uncaught exceptions 2020-03-16 20:32:59 +01:00
Kamil Śliwak
c7051e1386 [yul-phaser] Program: Explicitly return variants values
- Otherwise the code fails to build with on GCC 7.4.0 on Ubuntu in the CI pipeline
2020-03-16 20:32:59 +01:00
Kamil Śliwak
8ca0d90aae [yul-phaser] Returning an ErrorList from Program::load() if program has errors and printing them in Phaser 2020-03-16 20:32:59 +01:00
Kamil Śliwak
9ef63a9789 [yul-phaser] Program: Output operator for ErrorList
- It does not seem universal enough to put it in liblangutil but in the scope of yul-phaser it's generic enough so I'm going to keep it together with Program.
2020-03-16 20:32:59 +01:00
Kamil Śliwak
98fcba8ef3 [yul-phaser] Phaser: Reimplement << and >> operators using serializeChoice() and deserializeChoice() 2020-03-13 11:21:23 +01:00
Kamil Śliwak
deaf1d0c6f [yul-phaser] Add serializeChoice() and deserializeChoice() 2020-03-13 11:21:23 +01:00
Kamil Śliwak
0c3de9ef99 [yul-phaser] Add Common module 2020-03-13 11:21:23 +01:00
Kamil Śliwak
a80512a71d [yul-phaser] Phaser: Name option parameters in command-line help 2020-03-13 11:21:23 +01:00
Kamil Śliwak
df90cf5d7a [yul-phaser] Phaser: Make all option descriptions consistenly end with a full stop 2020-03-13 11:21:23 +01:00
Kamil Śliwak
ffc21632b6 [yul-phaser] Phaser: Split command-line option description into groups 2020-03-13 11:21:23 +01:00
Kamil Śliwak
7cf5c4e266 [yul-phaser] Phaser: Extract preparation of option description into a separate function 2020-03-13 11:21:23 +01:00
Kamil Śliwak
2d177c7623 [yul-phaser] Phaser: Refactor object creation in runAlgorithm() into a set of factories 2020-03-13 11:21:23 +01:00
Kamil Śliwak
25e81f6bd3 [yul-phaser] AlgorithmRunner: Count rounds from 1 2020-03-13 11:21:23 +01:00
Kamil Śliwak
2110bf10cf [yul-phaser] AlgorithmRunner: Create a structure to store runner's options 2020-03-13 11:21:23 +01:00
Kamil Śliwak
b8244f6a43 [yul-phaser] Extract the code that controls execution of algorithm rounds from GeneticAlgorithm into AlgorithmRunner 2020-03-13 11:21:23 +01:00
Kamil Śliwak
0c1b88508e [yul-phaser] Refactor the code from main into a Phaser class 2020-03-13 11:21:23 +01:00
Kamil Śliwak
3e3887dc9a [yul-phaser] main: Add missing underscores to parameter names 2020-03-13 11:21:23 +01:00
Kamil Śliwak
0fa2aa62b2 [yul-phaser] main: Lower gene mutation chance in GEWEP 2020-03-09 13:21:48 +01:00
Kamil Śliwak
763bdb1d51 [yul-phaser] Change the design of crossover operators so that they produce a single chromosome rather than a pair 2020-03-09 13:21:48 +01:00
cameel
a3e97108c5 [yul-phaser] main: Add GenerationalElitistWithExclusivePools as an option and make it the default 2020-03-09 13:21:48 +01:00
Kamil Śliwak
0c61f6d18f [yul-phaser] main: Command-line option for algorithm selection 2020-03-09 13:21:48 +01:00
Kamil Śliwak
fc4fedb214 [yul-phaser] Add GenerationalElitistWithExclusivePools algorithm 2020-03-09 13:21:48 +01:00
cameel
7e80ac861f [yul-phaser] Population: Add mutate() and crossover() methods 2020-03-09 13:21:48 +01:00
Kamil Śliwak
c941eaf5d6 [yul-phaser] Add randomPointCrossover() and fixedPointCrossover() operators 2020-03-09 13:21:48 +01:00
cameel
3fdb4ca607 [yul-phaser] Add geneRandomisation(), geneDeletion(), geneAddition and alternativeMutations() 2020-03-09 13:21:48 +01:00
Kamil Śliwak
f9f2bdb5f7 [yul-phaser] Add RandomPairSelection and PairMosaicSelection classes 2020-03-09 13:21:48 +01:00
cameel
44932dc85a [yul-phaser] Base class for pair selections 2020-03-09 13:21:48 +01:00
Kamil Śliwak
7c7ebbb35f [yul-phaser] main: Rename initializeRNG() to initialiseRNG() 2020-03-09 13:21:48 +01:00
Kamil Śliwak
66d733fbac [yul-phaser] main: Increase the number of chromosomes in the initial population to 20 2020-02-25 16:06:16 +01:00
Kamil Śliwak
3aaca31c31 [yul-phaser] main: Change the number of chromosomes preserved in every round of the algorithm to 1 2020-02-25 16:06:16 +01:00
Kamil Śliwak
4aac7d1673 [yul-phaser] main: Switch from using Population::run() to RandomAlgorithm 2020-02-25 16:06:16 +01:00
Kamil Śliwak
e1b8b64f05 [yul-phaser] Population: Remove no longer used methods for running algorithm steps
- They have been superseded by objects from GeneticAlgorithms.h
2020-02-25 16:06:16 +01:00
cameel
67fbafab8f [yul-phaser] Add RandomAlgorithm 2020-02-25 16:06:16 +01:00
cameel
4665b7a7e4 [yul-phaser] Population: Add select() method 2020-02-25 15:25:16 +01:00
cameel
83b8ab8012 [yul-phaser] Add RangeSelection, MosaicSelection and RandomSelection classes 2020-02-25 15:25:16 +01:00
cameel
3c41bfbc4e [yul-phaser] Base class for selections 2020-02-25 15:25:16 +01:00
cameel
11bdf358df [yul-phaser] Base class for genetic algorithms 2020-02-25 15:25:16 +01:00
Kamil Śliwak
e8192e9aa3 [yul-phaser] main: Set the number of optimisation sequence repetitions to 5 2020-02-19 17:26:34 +01:00
cameel
2291cf78ac [yul-phaser] Population: Add constructors to Individual to simplify initialization 2020-02-19 17:26:34 +01:00
cameel
cef01c961a [yul-phaser] Population: Keep the individuals always sorted 2020-02-19 17:26:34 +01:00
cameel
76842ac3fd [yul-phaser] Population: Evaluate fitness immediately when an individual is added or modified
- This removes the explicit evaluation phase.
- Fitness is no longer optional in Individual
2020-02-19 17:26:34 +01:00
cameel
66fdc1c374 [yul-phaser] Population: Store fitness metric rather than program directly
- In the console app use ProgramSize metric when creating the population.
2020-02-19 17:03:35 +01:00
cameel
85074e7a8a [yul-phaser] Population: Extract sorting from doSelection() into sortIndividuals() in Population class 2020-02-19 17:03:35 +01:00
cameel
41f36f421d [yul-phaser] Population: Extract conversion from chromosomes to individuals into a separate function 2020-02-19 17:03:35 +01:00
Kamil Śliwak
930a9918a6 [yul-phaser] ProgramSize: Add an option to repeat the optimisation sequence several times 2020-02-19 16:36:14 +01:00
cameel
2238919c76 [yul-phaser] Add ProgramSize metric 2020-02-19 16:36:14 +01:00
cameel
096129fbc4 [yul-phaser] Base class for fitness metrics 2020-02-19 16:36:14 +01:00
Kamil Śliwak
31d8d5930a [yul-phaser] Population: Equality operators for populations and individuals 2020-02-18 19:40:37 +01:00
cameel
d9c5e2dc9f [yul-phaser] Population: Add operator+() 2020-02-18 19:40:37 +01:00
Kamil Śliwak
ecb30c670f [yul-phaser] Population: Make ordering of individuals with same fitness deterministic and prioritise shorter chromosomes
- Before this change the order of chromosomes with the same fitness in a population depended on the initial order set when the population was first created. Now it only depends on the individual.
- The length comparison is not strictly necessary (lexicographical order covers that) but it makes the intention clear and the comparison slightly faster when chromosomes have different lengths.
2020-02-18 19:40:37 +01:00
Kamil Śliwak
40a6669538 [yul-phaser] Population: Extract a function for comparing fitness of individuals
- Mostly for readability and convenience. This significantly shortens calls to sort().
- I could define it as Individual::operator< instead but it would be inconsistent with operator== because it does not compare the chromosomes, only fitness. It could result in an unintuitive situation where (a <= b <= a) does not necessarily imply (a == b).
2020-02-18 19:40:37 +01:00
Kamil Śliwak
806891f494 [yul-phaser] Population: Customizable chromosome length in makeRandom() 2020-02-18 19:40:37 +01:00
Kamil Śliwak
d22c59aa0e [yul-phaser] Chromosome: Add a constructor that reads steps from an abbreviation string 2020-02-18 19:38:55 +01:00
cameel
71dcbf9df5 [yul-phaser] Population: Remove ambiguous default from one of the constructors 2020-02-18 19:38:55 +01:00
Kamil Śliwak
b3f595ce9d [yul-phaser] Population: Remove unused include for <iostream> 2020-02-18 19:38:55 +01:00
Kamil Śliwak
2f67302ffc [yul-phaser] main: Add --seed option 2020-02-16 02:18:21 +01:00
Kamil Śliwak
f29d3655f7 [yul-phaser] SimulationRNG: Add bernoulliTrial() 2020-02-16 02:18:21 +01:00
Kamil Śliwak
db140a667a [yul-phaser] SimulationRNG: Use a single, shared and seedable generator 2020-02-16 02:18:21 +01:00
Kamil Śliwak
342a4e5dee [yul-phaser] Rename Random to SimulationRNG (fix references) 2020-02-16 02:18:21 +01:00
Kamil Śliwak
0d28d5a287 [yul-phaser] Rename Random to SimulationRNG (file move) 2020-02-16 02:18:21 +01:00
Kamil Śliwak
b01766c4db [yul-phaser] Gather functions from Random into SimulationRNG class 2020-02-16 02:18:21 +01:00
Kamil Śliwak
4ee9174454 [yul-phaser] Chromosome: Make randomOptimisationStep() public
- And add tests now that it's public.
2020-02-16 02:18:21 +01:00
chriseth
f0ebb26f29
Merge pull request #8223 from imapp-pl/yul-phaser-program-reuse
[yul-phaser] Program reuse
2020-02-06 13:29:44 +01:00
Daniel Kirchner
9b8e3800bb Fix upgrade tool build on windows. 2020-02-06 10:49:15 +01:00
cameel
e4c7b73897 [yul-phaser] Store already loaded program in Population and make copies when computing fitness
- Until now the source code was being parsed during every fitness computation. Now the parsed program is reused and only the optimisation steps are applied each time.
2020-02-06 09:01:10 +01:00
cameel
57fb64d467 [yul-phaser] Make Program copyable by doing a deep copy of the AST in the copy constructor 2020-02-06 09:01:10 +01:00
cameel
a189c8b6e2 [yul-phaser] Pass unique_ptr rather than a mutable reference to Program::applyOptimisationSteps()
- Giving the function ownership of an object and then receiving back another object is better than letting it implicitly modify data passed in an argument.
2020-02-06 09:01:10 +01:00
cameel
785f65d0f5 [yul-phaser] Make Program and Population classes accept source code rather than file path
- I need some sample .yul files for testing but I see that existing tests generally have source code hard-coded in them rather than in standalone .yul files. There are lots of .yul files but they seem to be automatically processed by a special test case rather loaded ad-hoc by manually created tests.
- Program and Population required a file name until now. I'm making them accept loaded source code to be able to give them data hard-coded in a test.
2020-02-05 18:13:30 +01:00
cameel
7b7c88ae95 [yul-phaser] Add Population class 2020-02-05 18:13:30 +01:00
cameel
f0fb046038 [yul-phaser] Remove Chromosome::allStepNamesExcept() 2020-02-05 18:13:30 +01:00
cameel
f6d955db0b [yul-phaser] Add Chromosome class 2020-02-05 18:13:30 +01:00
cameel
57ab8922cd [yul-phaser] Add random number generators using Mersenne Twister from boost 2020-02-05 18:13:30 +01:00
cameel
21a2b69f74 [yul-phaser] Create OptimiserStepContext on demand instead of storing it in Program class
- This also lets us get rid of the static s_externallyUsedIdentifiers.
2020-02-05 18:13:30 +01:00
cameel
3baa191b94 [yul-phaser] Printing and JSON conversion for the Program class 2020-02-05 18:13:30 +01:00
cameel
2aa42b32e5 [yul-phaser] Make Program noncopyable
- Copying worked but resulted in OptimiserStepContext having a reference to NameDispenser instance of the other object.
2020-02-05 18:13:30 +01:00
cameel
14d726ff01 [yul-phaser] Program: Use unique_ptr rather than shared_ptr to hold a pointer to the AST root
- The class never shares the instance so unique_ptr makes more sense.
2020-02-05 18:13:30 +01:00
cameel
513d41c315 [yul-phaser] Add Program class 2020-02-05 18:13:30 +01:00
cameel
b75370d93e [yul-phaser] Printing help and accepting input file on the command line 2020-02-05 18:13:30 +01:00
cameel
e7d204383d [yul-phaser] An empty command-line application for the new tool 2020-02-05 18:13:29 +01:00
Erik Kundt
f2701db0aa Adds documentation for Solidity source upgrader. 2020-02-05 16:52:54 +01:00