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

governify-csp-tools

v0.3.7

Published

Governify CSP Tools

Downloads

10

Readme

Governify CSP Tools

This is a Node.js module created to provide Constraint Satisfaction Problems (CSP) tools, such as:

  • Reasoner: solves a CSP in three different environments: local, remote and docker.
  • CSP model: defines a CSP on a JavaScript object based on MiniZinc language.
  • Builders: creates a CSP model from another model, e.g. AgreementMinizincBuilder(TODO:link)
  • Translators: translates a CSP model from a language to another language, e.g. CSPModelMinizincTranslator(TODO:link) and MinizincCSPModelTranslator(TODO:link)

Governify CSP Tools solves CSP by using:

  • MiniZinc, a free and open-source constraint modeling language.
  • GeCode, a toolkit for developing constraint-based systems and applications.

Governify CSP Tools executions relies on these command lines:

  • mzn2fzn
  • fzn-gecode
  • solns2out

Make sure you have these commands working if you want to execute the Reasoner on local.

This module follows the project-template-nodejs developing guidelines.

Install

npm install governify-csp-tools

Basic Usage

// Import
var Reasoner = require("governify-csp-tools").Reasoner;

// Define your CSP on a JavaScript object
var cspModel = {
  "variables": [
    {
      "id": "Var1",
      "type": "int"
    },
    {
      "id": "Var2",
      "range": {
        "min": "0",
        "max": "10"
      }
    }
  ],
  "constraints": [
    {
      "id": "C1",
      "expression": "Var1 == 0 -> Var2 <= 1"
    },
    {
      "id": "C2",
      "expression": "Var1 == 0"
    }
  ],
  "goal": "satisfy"
};

// Configure the CSP reasoner
var reasoner = new Reasoner({
    type: 'local', // type value also can be 'api' or 'docker'
    folder: 'csp_files' // name of the folder which stores .mzn, .fzn and .ozn temporary files
});

// Solve CSP
reasoner.solve(cspModel, (err, stdout, stderr, isSatisfiable) => {
    if (err) {
        // manage error
    } else {
        // manage solution
    }
});

You can define your CSP model by following the CSP schema.

Reasoner can also be configured to execute on remote (API) or docker. Take a look in reasoner configuration.

Reasoner configuration

This tool is responsible for executing and solving a CSP. The Reasoner can be configured to run in three different environments: local, remote (api) and docker.

Follow the configuration examples to set your reasoner or take a look on reasoner configuration schema.

Local configuration

To use this feature, you need to install mzn2fzn, fzn-gecode and solns2out commands. You can easily install all these commands by installing MiniZinc IDE available for Windows, Mac OS X or Linux.

Make sure you have these commands working before running reasoner on local.

To set your reasoner configuration on local you need to set type:"local", e.g.:

{
  "type": "local",
  "folder": "csp_files"
}

Remote configuration

You need to set "type":"api" and define api object on reasoner configuration, for example:

{
  "type": "api",
  "folder": "csp_files",
  "api": {
    "version": "v2",
    "server": "https://minizinc.modules.designer.governify.io/module-minizinc",
    "operationPath": "models/csp/operations/execute"
  }
}

In the example, the final API endpoint will be: https://localhost/csp/api/v1/operations/execute

Docker configuration

To use this feature, you will need to have docker installed on the machine you are requiring governify-csp-tools.

To set your reasoner configuration on local you need to set type:"docker", e.g.:

{
  "type": "docker",
  "folder": "csp_files"
}

Reasoner schema

Please, follow the schema to set your reasoner configuration:

---
title: Reasoner configuration schema
type: 'object'
properties:
  type:
    enum:
    - 'local'
    - 'api'
    - 'docker'
  folder: # define a folder name to save .mzn, .fzn and .ozn temporary files
    type: 'string' 
  api: # only if type is 'api'
    type: 'object'
    properties:
      version:
        type: 'string'
      server:
        type: 'string'
      operationPath:
        type: 'string'
required:
  - 'type'
  - 'folder'

CSP model schema

This schema has been created to describe CSP problem on YAML, which in turn can be translated to MiniZinc afterward.

By now, this schema allows you to define:

  • Parameters.
  • Variables.
  • Constraints.
  • Goal.

The CSP model JSON schema expressed on YAML is:

---
title: 'CSP model JSON schema'
type: 'object'
properties:
  parameters:
    type: 'array'
    items:
      type: 'object'
      properties:
        id:
          type: 'string'
        type:
          enum:
            - 'bool'
            - 'boolean'
            - 'double'
            - 'float'
            - 'int32'
            - 'int64'
            - 'integer'
            - 'number'
        value:
          type: 'string'
        values: # only for 'enum' type
          type: 'array'
          items:
            type: 'string'
      required:
        - 'id'
        - 'type'
  variables:
    type: 'array'
    items:
      type: 'object'
      properties:
        id:
          type: 'string'
        type:
          type: 'string'
        range:
          type: 'object'
          properties:
            min:
              type: 'string'
            max:
              type: 'string'
      required:
        - 'id'
  constraints:
    type: 'array'
    items:
      type: 'object'
      properties:
        id:
          type: 'string'
        expression:
          type: 'string'
      required:
        - 'id'
        - 'expression'
  goal:
    type: 'string'
required:
  - 'variables'
  - 'constraints'
  - 'goal'

Latest release

The version 0.3.6 is the latest stable version of governify-csp-tools component. see release note for details.

For running:

  • Download latest version from 0.3.6