Random with SEEED
This commit is contained in:
@@ -2,6 +2,7 @@ import {AdditionalNode, GraphNode, GraphNodeWithIds, isAdditionalNode} from "./t
|
||||
import {Dict} from "../types";
|
||||
import deepcopy from "deepcopy";
|
||||
import {isNonNullable, shuffleInplace, sortByProperty, uniquify} from "../utils";
|
||||
import seedrandom from "seedrandom";
|
||||
|
||||
|
||||
|
||||
@@ -212,6 +213,7 @@ export function findBest<T extends Dict<unknown>>(rowsWithInOut: string[][], nod
|
||||
let bestRows = deepcopy(rowsWithInOut)
|
||||
let limit = Date.now() + timeLimit
|
||||
let iterSinceImprovements = 0
|
||||
let rng = seedrandom.alea("We are SEEED, ya!")
|
||||
while (true) {
|
||||
if (Date.now() > limit) break
|
||||
if (iterSinceImprovements > 100) break
|
||||
@@ -223,7 +225,7 @@ export function findBest<T extends Dict<unknown>>(rowsWithInOut: string[][], nod
|
||||
} else {
|
||||
iterSinceImprovements++
|
||||
}
|
||||
rowsOptimized.forEach(shuffleInplace)
|
||||
rowsOptimized.forEach((row, ) => shuffleInplace(row, rng))
|
||||
}
|
||||
console.log(bestScore)
|
||||
return bestRows
|
||||
@@ -244,9 +246,5 @@ export function graphUntangled<T extends Dict<unknown>>(nodes: GraphNode<T>[], i
|
||||
//console.table(rowsWithInOut)
|
||||
//console.table(nodesLinked)
|
||||
const bestRows = findBest(rowsWithInOut, nodesWithInOut, timeLimit)
|
||||
const orderRow = bestRows.find(row => row.length > 1)
|
||||
if ((orderRow?.[0]?.localeCompare(orderRow[orderRow.length-1]) ?? 0) > 0) {
|
||||
bestRows.forEach(row => row.reverse())
|
||||
}
|
||||
return [bestRows, nodesLinked]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user