Skip to content

Commit

Permalink
WorldConfig added to separate config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed May 27, 2024
1 parent 6a1c8be commit f6db9b0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
20 changes: 20 additions & 0 deletions data/input/default-genetic-world-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"VIEW_MODE": "2d",
"PHYSIC_MODEL": "v2",
"ATOM_RADIUS": 5,
"MAX_INTERACTION_RADIUS": 100,
"MAX_LINK_RADIUS": 60,
"MAX_FORCE": 0.4,
"GRAVITY_FORCE_MULTIPLIER": 1,
"LINK_FORCE_MULTIPLIER": 0.015,
"BOUNCE_FORCE_MULTIPLIER": 2,
"BOUNDS_FORCE_MULTIPLIER": 0.01,
"INERTIAL_MULTIPLIER": 0.96,
"SPEED": 25,
"PLAYBACK_SPEED": 1,
"SIMPLIFIED_VIEW_MODE": false,
"TEMPERATURE_MULTIPLIER": 0,
"CONFIG_2D": null,
"CONFIG_3D": null,
"TEMPERATURE_FUNCTION": null
}
8 changes: 4 additions & 4 deletions src/lib/config/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export function createBaseWorldConfig(): WorldConfig {
};
}

export function createWorldConfig2d(initialConfig: InitialConfig): WorldConfig {
export function createWorldConfig2d(initialConfig: InitialConfig, worldConfig?: WorldConfig): WorldConfig {
return {
...createBaseWorldConfig(),
...(worldConfig ?? createBaseWorldConfig()),
VIEW_MODE: '2d',
CONFIG_2D: {
...createBaseWorldConfig().CONFIG_2D,
Expand All @@ -62,9 +62,9 @@ export function createWorldConfig2d(initialConfig: InitialConfig): WorldConfig {
}


export function createWorldConfig3d(initialConfig: InitialConfig): WorldConfig {
export function createWorldConfig3d(initialConfig: InitialConfig, worldConfig?: WorldConfig): WorldConfig {
return {
...createBaseWorldConfig(),
...(worldConfig ?? createBaseWorldConfig()),
VIEW_MODE: '3d',
CONFIG_3D: {
...createBaseWorldConfig().CONFIG_3D,
Expand Down
6 changes: 5 additions & 1 deletion src/scripts/actions/genetic-search-by-types-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const actionGeneticSearchByTypesConfig = async (...args: string[]) => {
crossoverRandomizeConfigFileName,
referenceConfigFileName,
weightsFileName,
worldConfigFileName,
} = argsMap;
console.log('[INPUT PARAMS]', argsMap);
console.log(`[START] genetic search action (process_id = ${runId})`);
Expand All @@ -42,7 +43,7 @@ export const actionGeneticSearchByTypesConfig = async (...args: string[]) => {
crossoverRandomizeConfig: getRandomizeConfig(crossoverRandomizeConfigFileName),
referenceTypesConfig: getTypesConfig(referenceConfigFileName),
weights: getWeights(weightsFileName),
worldConfig: getWorldConfig(mainConfig.initial),
worldConfig: getWorldConfig(worldConfigFileName, mainConfig.initial),
};

console.log('[START] Building genetic search');
Expand Down Expand Up @@ -88,6 +89,8 @@ function parseArgs(argsParser: ArgsParser) {
const mutationRandomizeConfigFileName = argsParser.getString('mutationRandomizeConfigFileName', randomizeConfigFileName);
const crossoverRandomizeConfigFileName = argsParser.getString('crossoverRandomizeConfigFileName', randomizeConfigFileName);

const worldConfigFileName = argsParser.getString('worldConfigFileName', 'default-genetic-world-config');

return {
poolSize,
generationsCount,
Expand All @@ -97,5 +100,6 @@ function parseArgs(argsParser: ArgsParser) {
crossoverRandomizeConfigFileName,
referenceConfigFileName,
weightsFileName,
worldConfigFileName,
};
}
6 changes: 5 additions & 1 deletion src/scripts/actions/random-search-by-types-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const actionRandomSearchByTypesConfig = async (...args: string[]) => {
sourceConfigFileName,
referenceConfigFileName,
weightsFileName,
worldConfigFileName,
} = argsMap;
console.log('[INPUT PARAMS]', argsMap);
console.log(`[START] random search action (process_id = ${runId})`);
Expand All @@ -44,7 +45,7 @@ export const actionRandomSearchByTypesConfig = async (...args: string[]) => {
sourceTypesConfig: getTypesConfig(sourceConfigFileName),
referenceTypesConfig: getTypesConfig(referenceConfigFileName),
weights: getWeights(weightsFileName),
worldConfig: getWorldConfig(mainConfig.initial),
worldConfig: getWorldConfig(worldConfigFileName, mainConfig.initial),
};

console.log('[START] Building genetic search');
Expand Down Expand Up @@ -88,6 +89,8 @@ function parseArgs(argsParser: ArgsParser) {
const mutationRandomizeConfigFileName = argsParser.getString('mutationRandomizeConfigFileName', randomizeConfigFileName);
const crossoverRandomizeConfigFileName = argsParser.getString('crossoverRandomizeConfigFileName', randomizeConfigFileName);

const worldConfigFileName = argsParser.getString('worldConfigFileName', 'default-genetic-world-config');

return {
poolSize,
generationsCount,
Expand All @@ -98,5 +101,6 @@ function parseArgs(argsParser: ArgsParser) {
sourceConfigFileName,
referenceConfigFileName,
weightsFileName,
worldConfigFileName,
};
}
6 changes: 4 additions & 2 deletions src/scripts/lib/genetic/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export function getRandomizeConfig(fileName: string): RandomTypesConfig {
return readJsonFile(`data/input/${fileName}`) as RandomTypesConfig;
}

export function getWorldConfig(initialConfig: InitialConfig): WorldConfig {
return createWorldConfig2d(initialConfig);
export function getWorldConfig(fileName: string, initialConfig: InitialConfig): WorldConfig {
const worldConfig = readJsonFile(`data/input/${fileName}`) as WorldConfig;
worldConfig.TEMPERATURE_FUNCTION = () => 1;
return createWorldConfig2d(initialConfig, worldConfig);
}

export function getWeights(fileName: string): TotalSummaryWeights {
Expand Down

0 comments on commit f6db9b0

Please sign in to comment.