JWally / jsLPSolver

Simple OOP javaScript library to solve linear programs, and mixed integer linear programs
The Unlicense
420 stars 69 forks source link

HTML JS usage #107

Closed GittyGenie closed 4 years ago

GittyGenie commented 4 years ago

Hi, can jsLPSolver be used without using Node and just wrapped in a html page? Sorry if this is a dumb question, but the examples on the Readme use "require" not recognized by browser js. Thanks, Hoss

JWally commented 4 years ago

I think there's a web friendly version inside of 'src/solver.js'

redblobgames commented 3 years ago

An example of loading solver.js in the browser without require():

<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}
    }
};

// note that "solver" will be a global variable so you don't need to require() it
results = solver.Solve(model);
console.log(results);
</script>