TypeScript implementation of the Simplex algorithm for linear programming optimization.
type Table = {
header: string[],
rows: TableRow[],
z_row: number[]
}const problem: Table = {
header: ["x1", "x2", "x3", "x4", "x5", "b"],
rows: [
{ basic_var: "x3", coefficients: [5, 3, 1, 0, 0, 30] },
{ basic_var: "x4", coefficients: [2, 3, 0, 1, 0, 24] },
{ basic_var: "x5", coefficients: [1, 3, 0, 0, 1, 18] }
],
z_row: [-8, -6, 0, 0, 0, 0]
}
const solution = solve_simplex(problem);- Find entering variable (most negative in z-row)
- Minimum ratio test → leaving variable
- Pivot and normalize
- Repeat until optimal
verify_z_negative()/verify_z_positive()- Select entering variableverify_row_and_perform_header_swap()- Minimum ratio testcompute_row_reduction()- Gauss-Jordan eliminationsolve_simplex()- Main solver
TypeScript implementation for capacity planning and server sizing. Useful to determine needs for load balancers during high frequency trading.
interface QueueMetrics {
lambda: number; // arrival rate (transactions/hour)
mu: number; // service rate per server (transactions/hour)
s: number; // number of servers
}// Example: 1200 trades/hour, 3 seconds per trade, 2 workers
const lambda = 1200;
const mu = 1200; // 1/(3/3600) transactions/hour per server
const s = 2;
const rho = compute_utilization(lambda, mu, s); // 0.5
const decision = should_scale(lambda, mu, s);- Calculate ρ = λ / (s × μ)
- If ρ > 0.7 → add servers
- If ρ < 0.3 → remove servers
- Target: 0.5 ≤ ρ ≤ 0.7
compute_utilization()- Calculate ρshould_scale()- Auto-scaling decisionfactorial()- Helper for Erlang-C