Skip to content

Commit c047d4c

Browse files
committed
fix(portfolio-contract): Propagate graph arc minimum flow into LP solver input
1 parent cd6ce39 commit c047d4c

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/portfolio-contract/tools/network/buildGraph.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface FlowEdge {
2121
src: AssetPlaceRef;
2222
dest: AssetPlaceRef;
2323
capacity?: number; // numeric for LP; derived from bigint
24+
min?: number; // numeric for LP; derived from bigint
2425
variableFee: number; // cost coefficient per unit flow in basis points
2526
fixedFee?: number; // optional fixed cost (cheapest mode)
2627
timeFixed?: number; // optional time cost (fastest mode)
@@ -260,6 +261,7 @@ export const makeGraphFromDefinition = (
260261
for (const link of spec.links) {
261262
addOrReplaceEdge(link.src, link.dest, {
262263
capacity: link.capacity === undefined ? undefined : Number(link.capacity),
264+
min: link.min === undefined ? undefined : Number(link.min),
263265
variableFee: link.variableFeeBps ?? 0,
264266
fixedFee: link.flatFee === undefined ? undefined : Number(link.flatFee),
265267
timeFixed: link.timeSec,

packages/portfolio-contract/tools/network/network-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export interface LinkSpec {
9090
feeMode?: FeeMode; // how fees apply to transation using this link. See plan-solve.ts
9191

9292
// Policy / guardrails (optional)
93-
priority?: number; // tie-break hint
94-
enabled?: boolean; // admin toggle
93+
// priority?: number; // tie-break hint
94+
// enabled?: boolean; // admin toggle
9595
}
9696

9797
// Overall network definition

packages/portfolio-contract/tools/plan-solve.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ export const buildLPModel = (
145145
let minPrimaryWeight = Infinity;
146146
for (const edge of graph.edges) {
147147
const { id, src, dest } = edge;
148-
const { capacity, variableFee, fixedFee = 0, timeFixed = 0 } = edge;
148+
const { capacity, min, variableFee, fixedFee = 0, timeFixed = 0 } = edge;
149149

150-
const throughputConstraint: { min: number; max?: number } = { min: 0 };
151-
if (capacity) throughputConstraint.max = capacity;
152-
throughputConstraints[`through_${id}`] = throughputConstraint;
150+
throughputConstraints[`through_${id}`] = {
151+
min: min || 0,
152+
max: capacity,
153+
};
153154

154155
// The numbers in graph.supplies should use the same units as fixedFee, but
155156
// variableFee is in basis points relative to some scaling of those other
@@ -297,6 +298,7 @@ SUBJECT TO
297298
const prefix = attrParts.join('_');
298299
const lines = [`\\# ${attr} ${prettyJsonable(constraint)}`];
299300
for (const [opName, value] of Object.entries(constraint)) {
301+
if (!Number.isFinite(value)) continue;
300302
const label = `${prefix}_${opName.slice(0, 3)}`;
301303
const op = cplexLpOpForName[opName];
302304
lines.push(`${label}: ${makeSumExpr(attr)} ${op} ${value}`);

0 commit comments

Comments
 (0)