Skip to content

Commit

Permalink
heuristics progress
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Sep 23, 2024
1 parent 1ec33a4 commit 471254a
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 41 deletions.
71 changes: 43 additions & 28 deletions src/components/sections/results/table/ResultTableRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,52 @@ const ResultTableRow = ({
</Typography>
) : null}
</TableCell>
{padCellArray(
maxSlotsLength,
character.gear.map((affix, index) => {
let textDecoration;
if (exoticRarity(affix, index) && mostCommonRarity !== 'exotic')
textDecoration = 'underline dotted #ffa405';
if (!exoticRarity(affix, index) && mostCommonRarity !== 'ascended')
textDecoration = 'underline dotted #fb3e8d';
{character.gear.length > 1 ? (
padCellArray(
maxSlotsLength,
character.gear.map((affix, index) => {
let textDecoration;
if (exoticRarity(affix, index) && mostCommonRarity !== 'exotic')
textDecoration = 'underline dotted #ffa405';
if (!exoticRarity(affix, index) && mostCommonRarity !== 'ascended')
textDecoration = 'underline dotted #fb3e8d';

const affixFragments = affix.split(/(?=[A-Z])/).filter((fragment) => fragment !== 'And');
const multiWordAffix = affixFragments.length > 1;
const affixFragments = affix
.split(/(?=[A-Z])/)
.filter((fragment) => fragment !== 'And');
const multiWordAffix = affixFragments.length > 1;

const shortAffix = affixFragments
.map((fragment) => fragment.slice(0, multiWordAffix ? 3 : 4))
.join('');
const shortAffix = affixFragments
.map((fragment) => fragment.slice(0, multiWordAffix ? 3 : 4))
.join('');

return (
<TableCell align="center" padding="none">
<Typography
style={{
fontWeight: 300,
fontSize: '1rem',
textDecoration,
color: mostCommonAffix && mostCommonAffix !== affix ? '#00cccc' : 'inherit',
}}
>
{shortAffix}
</Typography>
</TableCell>
);
}),
return (
<TableCell align="center" padding="none">
<Typography
style={{
fontWeight: 300,
fontSize: '1rem',
textDecoration,
color: mostCommonAffix && mostCommonAffix !== affix ? '#00cccc' : 'inherit',
}}
>
{shortAffix}
</Typography>
</TableCell>
);
}),
)
) : (
<TableCell align="center" padding="none" colSpan={14}>
<Typography
style={{
fontWeight: 300,
fontSize: '1rem',
}}
>
{character.gear[0]}
</Typography>
</TableCell>
)}
{padCellArray(
2,
Expand Down
2 changes: 2 additions & 0 deletions src/state/optimizer-parallel/optimizerSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function createSettings(reduxState: RootState): Settings {
secondaryMaxInfusions,
infusionMode,
slots,
affixes,
affixesArray,
identicalArmor,
identicalRing,
Expand Down Expand Up @@ -140,6 +141,7 @@ export function createSettings(reduxState: RootState): Settings {
secondaryInfusion,
secondaryMaxInfusions,
infusionMode,
affixes,
slots,
affixesArray,
identicalArmor,
Expand Down
67 changes: 67 additions & 0 deletions src/state/optimizer/combinatorics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable id-length */
/* eslint-disable import/prefer-default-export */

// warning: not optimized
function binomialCoefficient(n: number, k: number) {
let result = 1;
for (let i = 1; i <= k; i++) {
result *= (n + 1 - i) / i;
}
return Math.round(result);
}

/**
* Generates every integer partition of n of exactly length k.
* Also known as the stars and bars problem.
*
* @example
* console.log([...iteratePartitions(5, 3)])
*
* // [
* // [0, 0, 5],
* // [0, 1, 4],
* // [0, 2, 3],
* // ...
* // [4, 1, 0],
* // [5, 0, 0]
* // ]
*
* @param {number} n - total items to partition
* @param {number} k - partitions
* @param {boolean} mutate - whether to repeatedly yield references to the same mutated array (faster)
* @yields {number[]}
*/
export function* iteratePartitions(
n: number,
k: number,
mutate = false,
): Generator<number[], void, void> {
if (k < 2) {
yield [n];
return;
}

const current: number[] = new Array(k).fill(0);

function* inner(currentCup: number, currentBalls: number): Generator<number[], void, void> {
if (currentCup === k - 1) {
current[currentCup] = currentBalls;
yield mutate ? current : [...current];
} else {
for (let i = 0; i <= currentBalls; i++) {
current[currentCup] = i;
for (const result of inner(currentCup + 1, currentBalls - i)) {
yield result;
}
}
}
}

for (const result of inner(0, n)) {
yield result;
}
}

export function iteratePartitionCount(n: number, k: number) {
return binomialCoefficient(k + n - 1, n);
}
Loading

0 comments on commit 471254a

Please sign in to comment.