Skip to content

Commit

Permalink
Genetic helpers refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed May 20, 2024
1 parent ba0ab7a commit fcb6543
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
33 changes: 32 additions & 1 deletion src/lib/config/world.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WorldConfig } from '../types/config';
import type { BoundsConfig, InitialConfig, WorldConfig } from '../types/config';
import type { NumericVector } from '../math/types';

export function createBaseWorldConfig(): WorldConfig {
Expand Down Expand Up @@ -45,3 +45,34 @@ export function createBaseWorldConfig(): WorldConfig {
},
};
}

export function createWorldConfig2d(initialConfig: InitialConfig): WorldConfig {
return {
...createBaseWorldConfig(),
VIEW_MODE: '2d',
CONFIG_2D: {
...createBaseWorldConfig().CONFIG_2D,
INITIAL: initialConfig,
BOUNDS: {
MIN_POSITION: initialConfig.MIN_POSITION,
MAX_POSITION: initialConfig.MAX_POSITION,
},
},
};
}


export function createWorldConfig3d(initialConfig: InitialConfig): WorldConfig {
return {
...createBaseWorldConfig(),
VIEW_MODE: '3d',
CONFIG_3D: {
...createBaseWorldConfig().CONFIG_3D,
INITIAL: initialConfig,
BOUNDS: {
MIN_POSITION: initialConfig.MIN_POSITION,
MAX_POSITION: initialConfig.MAX_POSITION,
},
},
};
}
16 changes: 6 additions & 10 deletions src/scripts/actions/test-simulation-parallel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os from 'os';
import { Pool } from "multiprocess-pool";
import type { TypesConfig, WorldConfig } from '@/lib/types/config';
import { createBaseWorldConfig } from '@/lib/config/world';
import { createWorldConfig2d } from '@/lib/config/world';
import { createBaseTypesConfig } from '@/lib/config/types';
import {
convertWeightsToSummaryMatrixRow,
Expand Down Expand Up @@ -32,25 +32,20 @@ export const actionTestSimulationParallel = async (...args: string[]) => {
console.log('[START] test parallel simulation action', args);
const ts = Date.now();

const worldConfig = createBaseWorldConfig();
const typesConfig = createBaseTypesConfig();
const typesCount = typesConfig.FREQUENCIES.length;

const stepsCount = [300, 5, 5, 5, 5];
const atomsCount = 500;
const minPosition = [0, 0];
const maxPosition = [1000, 1000];

worldConfig.CONFIG_2D.INITIAL = {
const initialConfig = {
ATOMS_COUNT: atomsCount,
MIN_POSITION: minPosition,
MAX_POSITION: maxPosition,
};

worldConfig.CONFIG_2D.BOUNDS = {
MIN_POSITION: minPosition,
MAX_POSITION: maxPosition,
};
const worldConfig = createWorldConfig2d(initialConfig);
const typesConfig = createBaseTypesConfig();
const typesCount = typesConfig.FREQUENCIES.length;

const inputs = [];
for (let i = 0; i < 10; i++) {
Expand All @@ -70,6 +65,7 @@ export const actionTestSimulationParallel = async (...args: string[]) => {

console.log(normalizedMatrix);

console.log(weights);
console.log(summaries[0].length);
console.log(weights.length);
console.log(indexes.flat(1).length);
Expand Down

0 comments on commit fcb6543

Please sign in to comment.