Updating license #39
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user