Open Nick-Hope opened 3 years ago
Yes, require
is for node (or bundlers). You don't need it when using the CDN. When using the CDN, solver
is a global so you don't have to require it. Try this:
<script src="https://unpkg.com/javascript-lp-solver/prod/solver.js"></script>
<script>
var results,
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}
}
};
results = solver.Solve(model);
console.log(results);
</script>
Thank you @redblobgames and sorry for the very long delay in my response. That solved my issue and got it working.
I would like to use jsLPSolver locally in a browser, not running Node.js. I'm using the line from the 'in browser through CDN' section of the Install section of the README.
I tried the exact example in the "Use" section, but get the error
Uncaught ReferenceError: require is not defined
. It looks like the require.js library might offer a workaround for that, for those not using Node.js. But then I found an example without using require() from JWally. However when I run that in the script shown below, I get the errorUncaught ReferenceError: Solver is not defined
in my console.How can I resolve this? Feels like I'm missing something fundamental.