npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-knapsack

v1.0.0

Published

A Node-RED node that demonstrates the use of the Knapsack algorithm

Downloads

1

Readme

node-red-contrib-knapsack

node-red-contrib-knapsack is a Node-RED module that provides a node to solve the 0/1 Knapsack problem. This module helps users optimize allocation of items within a limited capacity constraint while maximizing the total value.

Installation

Install the node-red-contrib-knapsack module using the following command in your Node-RED user directory (usually ~/.node-red):

npm install node-red-contrib-knapsack

After installation, the knapsack node will be available in the Node-RED palette under the "function" category.

Usage

The knapsack node accepts an array of objects representing items, each with a value and weight property, and a maximum capacity constraint.

Input

The input message should have the following structure:

msg.payload = {
  items: [
    { value: <number>, weight: <number> },
    ...
  ],
  capacity: <number>
};
  • items: An array of objects, where each object represents an item with a value (positive number) and a weight (positive number).
  • capacity: A positive number representing the maximum capacity constraint.

Output

The output message will have the following structure:

msg.payload = {
  maxValue: <number>,
  selectedItems: [
    { value: <number>, weight: <number> },
    ...
  ]
};
  • maxValue: The maximum total value of the selected items within the capacity constraint.
  • selectedItems: An array of objects representing the selected items to include in the knapsack.

Example

  1. Drag and drop an inject node onto the Node-RED canvas.
  2. Double-click the inject node to open its configuration window, and configure the payload as follows:
{
  "items": [
    { "value": 60, "weight": 10 },
    { "value": 100, "weight": 20 },
    { "value": 120, "weight": 30 }
  ],
  "capacity": 50
}
  1. Drag and drop the knapsack node onto the canvas and connect it to the inject node.
  2. Drag and drop a debug node onto the canvas and connect it to the knapsack node.
  3. Deploy the flow.
  4. Click on the inject node's button to send the input message. The debug node will display the output message with the maximum value and selected items.

License

GPL-3.0

Contributing

Contributions to node-red-contrib-knapsack are welcome. Please follow the standard guidelines for contributing to open-source projects, and make sure to test your changes before submitting a pull request.

Author

node-red-contrib-knapsack is written by Harshad Joshi