Design fixes #50

Merged
SinusFox merged 62 commits from design-fixes into main 2024-10-11 14:23:53 +00:00
2 changed files with 113 additions and 0 deletions
Showing only changes of commit eca347ae09 - Show all commits
+36
View File
@@ -0,0 +1,36 @@
type VariableLP = { name: string; coef: number };
type ConstraintLP = {
name: string;
vars: VariableLP[];
bnds: { ub: number; lb: number };
};
interface ProblemLP {
objective: {
vars: VariableLP[];
};
constraints: ConstraintLP[];
}
function createProblemLP(
objectiveVars: VariableLP[],
constraints: { name: string; vars: VariableLP[]; ub: number; lb: number }[]
): ProblemLP {
const constraintsFormatted: ConstraintLP[] = constraints.map((constraint) => ({
name: constraint.name,
vars: constraint.vars,
bnds: {
ub: constraint.ub,
lb: constraint.lb
}
}));
const problem: ProblemLP = {
objective: {
vars: objectiveVars
},
constraints: constraintsFormatted
};
return problem;
}
+77
View File
@@ -0,0 +1,77 @@
interface VariableMIP {
name: string;
coef: number;
}
interface Bounds {
type: number;
ub: number;
lb: number;
}
interface ConstraintMIP {
name: string;
vars: VariableMIP[];
bnds: Bounds;
}
interface Options {
mipgap: number;
tmlim: number;
msglev: number;
}
interface Problem {
name: string;
objective: {
direction: "min" | "max";
name: string;
vars: VariableMIP[];
};
constraints: ConstraintMIP[];
binaries?: string[];
generals?: string[];
options: Options;
}
function createProblemMIP(
name: string,
direction: "min" | "max",
objectiveName: string,
objectiveVars: VariableMIP[],
constraints: { name: string; vars: VariableMIP[]; bnds_type: number; ub: number; lb: number }[],
binaries: string[],
generals: string[] = [],
mipgap: number,
tmlim: number,
msglev: number
): Problem {
const constraintsFormatted: ConstraintMIP[] = constraints.map((constraint) => ({
name: constraint.name,
vars: constraint.vars,
bnds: {
type: constraint.bnds_type,
ub: constraint.ub,
lb: constraint.lb
}
}));
const problem: Problem = {
name: name,
objective: {
direction: direction,
name: objectiveName,
vars: objectiveVars
},
constraints: constraintsFormatted,
binaries: binaries.length > 0 ? binaries : undefined,
generals: generals.length > 0 ? generals : undefined,
options: {
mipgap: mipgap,
tmlim: tmlim,
msglev: msglev
}
};
return problem;
}