-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
299 lines (217 loc) · 9.17 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
declare module "javascript-lp-solver" {
/**
* Specifies how to constrain a variable in the model.
*/
export interface IModelVariableConstraint {
/** The variable should be grater or equal to this value. */
min?: number;
/** The variable should be less or equal to this value. */
max?: number;
/** The variable should be equal to this value. */
equal?: number;
}
/**
* Specifies the options when solving the problem.
*/
export interface IModelOptions {
/**
* For MILP problems, specifies the relative tolerance of the objective,
* where `0` means 0% and `1` means 100%.
*/
tolerance?: number;
/**
* How many milliseconds you want to allow for the solver to try
* and solve the model you're running.
*/
timeout?: number;
/**
* Use MIR cuts.
* @deprecated NOT WORKING
*/
useMIRCuts?: boolean;
/**
* Defaults to `true`.
*/
exitOnCycles?: boolean;
}
/**
* Represents an LP/MILP problem.
* @typeparam TSolutionVar the decision variables that will be outputed to the `Solution` object.
* @typeparam TInternalVar the decision variables that will not be outputed to the `Solution` object.
*/
export interface IModel<TSolutionVar extends string = string, TInternalVar extends string = string> {
/** Name of the variable that will be the optimization objective. */
optimize: (TSolutionVar | TInternalVar);
/** To which direction to optimize the objective. */
opType: "max" | "min";
/**
* Optimization constraints.
* Specify an object with variable name as keys.
*/
constraints: { [variable in (TSolutionVar | TInternalVar)]?: IModelVariableConstraint };
/**
* Variable identity relations.
* Specify an object with variable name as keys. These variables will be outputted into solution.
* The values of the object represents a linear combination of all the (rest of) variables.
* @example
* ```
* {
* x: { x1: 10, x2: 5, x3: 2, x: 1 } // x = 10 x1 + 5 x2 + 2 x3
* }
* ```
*/
variables: { [variable in TSolutionVar]?: { [variable in (TSolutionVar | TInternalVar)]?: number } };
/**
* For each variable in the MILP problem, specifies whether it is an integer variable.
* You need to specify `true` or `1` for integer variable.
* If not specified, all the variables are continual non-negative (range `[0,+∞)`).
*/
ints?: { [variable in (TSolutionVar | TInternalVar)]?: boolean | 0 | 1 };
/**
* For each variable in the MILP problem, specifies whether it is a binary variable.
* You need to specify `true` or `1` for binary variable.
* If not specified, all the variables are continual non-negative (range `[0,+∞)`).
*/
binaries?: { [variable in (TSolutionVar | TInternalVar)]?: boolean | 0 | 1 };
/**
* For each variable in the MILP problem, specifies whether it is an unrestricted variable (range `(-∞,+∞)`).
* You need to specify `true` or `1` for unrestricted variable.
* If not specified, all the variables are continual non-negative (range `[0,+∞)`).
*/
unrestricted?: { [variable in (TSolutionVar | TInternalVar)]?: boolean | 0 | 1 };
/**
* Options for solving this problem.
*/
options?: IModelOptions;
}
/**
* Represents the solution status of an LP/MILP problem.
*/
export interface ISolutionStatus {
/** Whether the problem is feasible. */
feasible: boolean;
/** Value pf the objective function. */
result: number;
/** Whether the decision variables are bounded. */
bounded?: boolean;
/** For MILP problem, whether an integral solution has been reached. */
isIntegral?: boolean;
}
/**
* Represents a LP/MILP solution with its status.
* @remarks If a variable has value `0`, it will be neglected from the output.
*/
export type Solution<TSolutionVar extends string> = ISolutionStatus & { [variable in TSolutionVar]?: number };
/**
* Gets the last solved model.
*/
export const lastSolvedModel: IModel;
/**
* Converts the LP file content into a model object that jsLPSolver can handle.
* @param model Array of string containing raw content of model we want solver to operate on,
* each item is a line of content, without suffixing `"\n"`.
* See http://lpsolve.sourceforge.net/5.5/lp-format.htm for the spec.
*/
export function ReformatLP(model: string[]): IModel;
/**
* Convert a friendly JSON model into a model for a real solving library...
* in this case lp_solver.
* @param model The model we want solver to operate on.
*/
export function ReformatLP(model: IModel<any, any>): string;
/**
* Solves an LP/MILP problem.
* @param model The model we want solver to operate on.
* @param precision If we're solving a MILP, how tight
* do we want to define an integer, given
* that `20.000000000000001` is not an integer.
* (defaults to `1e-9`)
* @param full *get better description*
* @param validate if left blank, it will get ignored; otherwise
* it will run the model through all validation
* functions in the *Validate* module
*/
export function Solve<TSolutionVar extends string, TInternalVar extends string>(
model: IModel<TSolutionVar, TInternalVar>, precision?: number,
full?: boolean, validate?: unknown): Solution<TSolutionVar>;
//==================== WIP BELOW ====================//
// Members below this line are automatically generated and need to be sorted out.
// I will gradually move the members up across this line.
/** Declaration file generated by dts-gen */
export class Constraint {
constructor(rhs: any, isUpperBound: any, index: any, model: any);
addTerm(coefficient: any, variable: any): any;
relax(weight: any, priority: any): void;
removeTerm(term: any): any;
setRightHandSide(newRhs: any): any;
setVariableCoefficient(newCoefficient: any, variable: any): any;
}
export class Model {
constructor(precision: any, name: any);
activateMIRCuts(useMIRCuts: any): void;
addVariable(cost: any, id: any, isInteger: any, isUnrestricted: any, priority: any): any;
debug(debugCheckForCycles: any): void;
equal(rhs: any): any;
getNumberOfIntegerVariables(): any;
greaterThan(rhs: any): any;
isFeasible(): any;
loadJson(jsonModel: any): any;
log(message: any): any;
maximize(): any;
minimize(): any;
removeConstraint(constraint: any): any;
removeVariable(variable: any): any;
restore(): any;
save(): any;
setCost(cost: any, variable: any): any;
smallerThan(rhs: any): any;
solve(): any;
updateConstraintCoefficient(constraint: any, variable: any, difference: any): any;
updateRightHandSide(constraint: any, difference: any): any;
}
export class Tableau {
constructor(precision: any);
addConstraint(constraint: any): void;
addCutConstraints(cutConstraints: any): void;
addVariable(variable: any): void;
applyCuts(branchingCuts: any): void;
applyMIRCuts(): void;
branchAndCut(): void;
checkForCycles(varIndexes: any): any;
computeFractionalVolume(ignoreIntegerValues: any): any;
copy(): any;
countIntegerValues(): any;
density(): any;
getFractionalVarWithLowestCost(): any;
getMostFractionalVar(): any;
getNewElementIndex(): any;
getSolution(): any;
initialize(width: any, height: any, variables: any, unrestrictedVars: any): void;
isIntegral(): any;
log(message: any, force: any): any;
phase1(): any;
phase2(): any;
pivot(pivotRowIndex: any, pivotColumnIndex: any): void;
removeConstraint(constraint: any): void;
removeVariable(variable: any): void;
restore(): void;
save(): void;
setEvaluation(): void;
setModel(model: any): any;
setOptionalObjective(priority: any, column: any, cost: any): any;
simplex(): any;
solve(): any;
updateConstraintCoefficient(constraint: any, variable: any, difference: any): void;
updateCost(variable: any, difference: any): void;
updateRightHandSide(constraint: any, difference: any): void;
updateVariableValues(): void;
}
export const External: {
};
export const Numeral: any;
export const branchAndCut: {
};
export function MultiObjective(model: any): any;
export function Term(variable: any, coefficient: any): void;
export function Variable(id: any, cost: any, index: any, priority: any): void;
}