简体   繁体   中英

How can I use the jsLPSolver library locally in a browser?

I would like to use the jsLPSolver<\/a> library locally in a browser, not via Node.js, for running linear programming optimisations.

It looks like the require.js library might offer a workaround for that, for those not using Node.js. But then I found JWally's example However when I run that in the script shown below, I get the error Uncaught ReferenceError: Solver is not defined<\/code> in my console.

Feels like I may be missing something fundamental, that's not specific to jsLPSolver.

 <script src="https:\/\/unpkg.com\/javascript-lp-solver\/prod\/solver.js"><\/script> <script> const model = { optimize: "profit", opType: "max", constraints: { "Costa Rican": { max: 200 }, Etheopian: { max: 330 }, }, variables: { Yusip: { "Costa Rican": 0.5, Etheopian: 0.5, profit: 3.5 }, Exotic: { "Costa Rican": 0.25, Etheopian: 0.75, profit: 4 }, }, }; \/\/ We don't need to declare 'solver', it is already exported via the script we load const results = solver.Solve(model); \/\/ Note the capital '.Solve' console.log("Results", results); <\/script><\/code><\/pre>


Please try this. I believe your confusion comes from the documentation which uses an example interpreted via Node. You don't need to declare a solver variable, it is exported for you already via the imported script.

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM