Bookmark this: tool.io/generate/bipartite-matching-instance/source-code
Bipartite Matching Instance Generator Source Code
Browse the implementation files for Bipartite Matching Instance Generator.tool.ts typescript
import { parseFiniteNumber } from '../../parse/number/tool';
import { parseInteger } from '../../parse/integer/tool';
import { createSeededRandom } from '../../random/seeded-number/tool';
export const generateBipartiteMatchingInstance = (
leftInput: unknown,
rightInput: unknown,
probabilityInput: unknown,
seedInput: unknown
): string => {
const leftCount = parseInteger(leftInput);
const rightCount = parseInteger(rightInput);
const probability = parseFiniteNumber(probabilityInput);
if (
leftCount === null ||
leftCount < 1 ||
leftCount > 1000 ||
rightCount === null ||
rightCount < 1 ||
rightCount > 1000 ||
probability === null ||
probability < 0 ||
probability > 1 ||
typeof seedInput !== 'string' ||
!seedInput.trim()
)
return '';
const random = createSeededRandom(seedInput);
const edges: [number, number][] = [];
for (let left = 0; left < leftCount; left += 1)
for (let right = 0; right < rightCount; right += 1)
if (random() < probability) edges.push([left, right]);
return JSON.stringify(
{ edges, leftCount, rightCount, seed: seedInput },
null,
2
);
};
export const Tool: TypeTool = {
name: 'Bipartite Matching Instance Generator',
slug: 'generate/bipartite-matching-instance',
intro:
'Generate a reproducible random bipartite graph for matching experiments.',
tool: generateBipartiteMatchingInstance,
i: [
{
example: '5',
label: 'Left Vertices',
placeholder: 'Left partition size',
type: 'number'
},
{
example: '5',
label: 'Right Vertices',
placeholder: 'Right partition size',
type: 'number'
},
{
example: '0.4',
label: 'Edge Probability',
placeholder: 'Probability from 0 to 1',
type: 'number'
},
{
example: 'tool.io',
label: 'Seed',
placeholder: 'Reproducible seed',
type: 'text'
}
],
o: [
{
example: '{ "edges": [[0, 2]] }',
label: 'Instance',
placeholder: 'Instance will appear here...',
render: 'textarea',
type: 'text'
}
],
rerunnable: true,
cite: [
{
title: 'Matching (graph theory) - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Matching_(graph_theory)'
}
]
};
export default Tool;
Description
Browse the implementation files for Bipartite Matching Instance Generator.