Skip to content

Commit 136b2da

Browse files
📚 docs: Improve.
1 parent 0bbdb6d commit 136b2da

9 files changed

+29
-18
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
:school_satchel: [@problem-solving/knapsack](https://computational-problem-solving.github.io/knapsack)
22
==
33

4+
<p align="center">
5+
<a href="https://xkcd.com/287">
6+
<img src="https://imgs.xkcd.com/comics/np_complete.png" width="600">
7+
</a><br/>
8+
© <a href="https://xkcd.com">xkcd.com</a>
9+
</p>
10+
411
Knapsack problem algorithms for JavaScript.
512
See [docs](https://computational-problem-solving.github.io/knapsack/index.html).
613

7-
> :building_construction: Caveat emptor! This is work in progress. Code may be
8-
> working. Documentation may be present. Coherence may be. Maybe.
14+
```js
15+
import {
16+
knapsackGreedy,
17+
knapsackApprox,
18+
} from '@problem-solving/knapsack';
919

10-
> :warning: The code requires `regeneratorRuntime` to be defined, for instance by importing
11-
> [regenerator-runtime/runtime](https://www.npmjs.com/package/regenerator-runtime).
20+
knapsackGreedy(n, v, w, W); // 1/2 approximation
21+
knapsackApprox(eps, n, v, w, W); // 1-eps approximation
22+
```
1223

1324
[![License](https://img.shields.io/github/license/computational-problem-solving/knapsack.svg)](https://raw.githubusercontent.com/computational-problem-solving/knapsack/main/LICENSE)
1425
[![Version](https://img.shields.io/npm/v/@problem-solving/knapsack.svg)](https://www.npmjs.org/package/@problem-solving/knapsack)
@@ -27,4 +38,4 @@ See [docs](https://computational-problem-solving.github.io/knapsack/index.html).
2738
## :book: References
2839

2940
- The [knapsack problem](https://en.wikipedia.org/wiki/Knapsack_problem)
30-
explained in Wikipedia.
41+
explained at Wikipedia.

doc/manual/usage.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
# Usage
22

3-
> :warning: The code requires `regeneratorRuntime` to be defined, for instance by importing
4-
> [regenerator-runtime/runtime](https://www.npmjs.com/package/regenerator-runtime).
5-
6-
First, require the polyfill at the entry point of your application
7-
```js
8-
await import( 'regenerator-runtime/runtime.js' );
9-
// or
10-
import 'regenerator-runtime/runtime.js' ;
11-
```
12-
13-
Then, import the library where needed
3+
Import the library where needed
144
```js
15-
const knapsack = await import( '@problem-solving/knapsack' ) ;
5+
const knapsack = await import('@problem-solving/knapsack');
166
// or
17-
import * as knapsack from '@problem-solving/knapsack' ;
7+
import * as knapsack from '@problem-solving/knapsack';
188
```

src/integerValuesKnapsack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {sum} from '@iterable-iterator/reduce';
1212
* @param {Number} W Size of the knapsack.
1313
* @param {Number} V Any upper bound on OPT >= 0.
1414
* @param {Array} m Memory buffer.
15+
* @return {Number} Objective value of the optimum.
1516
*/
1617
const integerValuesKnapsack = (
1718
v,

src/integerValuesKnapsackUnbounded.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {range} from '@iterable-iterator/range';
1515
* @param {Number|BigInt} zero The number 0.
1616
* @param {Number} V Any upper bound on OPT >= 0.
1717
* @param {Array} m Memory buffer.
18+
* @return {Number} Objective value of the optimum.
1819
*/
1920
const integerValuesKnapsackUnbounded = (
2021
v,

src/integerWeightsKnapsack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import assert from 'assert';
99
* @param {Number} n Size of the problem.
1010
* @param {Number} W Size of the knapsack.
1111
* @param {Array} m Memory buffer.
12+
* @return {Number} Objective value of the optimum.
1213
*/
1314
const integerWeightsKnapsack = (
1415
v,

src/integerWeightsKnapsackUnbounded.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import assert from 'assert';
99
* @param {Number} n Size of the problem.
1010
* @param {Number} W Size of the knapsack.
1111
* @param {Array} m Memory buffer.
12+
* @return {Number} Objective value of the optimum.
1213
*/
1314
const integerWeightsKnapsackUnbounded = (
1415
v,

src/knapsackApprox.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import integerValuesKnapsack from './integerValuesKnapsack.js';
1616
* @param {Number} n Size of the problem.
1717
* @param {Number} W Size of the knapsack.
1818
* @param {Number} P Any lower bound on OPT > 0.
19+
* @return {Number} Lower bound on the objective value of a solution, that is
20+
* at least 1-eps the objective value of the optimum.
1921
*/
2022
const knapsackApprox = (
2123
eps,

src/knapsackGreedy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import orderedByDecreasingUtility from './orderedByDecreasingUtility.js';
2424
* @param {Array} w Weights.
2525
* @param {Number} n Size of the problem.
2626
* @param {Number} W Size of the knapsack.
27+
* @return {Number} Lower bound on the objective value of a solution, that is
28+
* at least half the objective value of the optimum.
2729
*/
2830
const knapsackGreedy = (v, w, n, W) => {
2931
assert(v.length === n);

src/knapsackUnboundedGreedy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import orderedByDecreasingUtility from './orderedByDecreasingUtility.js';
1414
* @param {Array} w Weights.
1515
* @param {Number} n Size of the problem.
1616
* @param {Number} W Size of the knapsack.
17+
* @return {Number} Lower bound on the objective value of a solution, that is
18+
* at least half the objective value of the optimum.
1719
*/
1820
const knapsackUnboundedGreedy = (v, w, n, W) => {
1921
assert(v.length === n);

0 commit comments

Comments
 (0)