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

preference_optimization

v0.0.3

Published

Given a top N list of preferences between lists A & B and X maximum matches, maximise...something.

Downloads

1

Readme

preference_optimization

Given a top N list of preferences between lists A & B and X maximum matches, maximise...something.

Download

This is a typescript package, but should be interoperable with Javascript. Check out this package on npmjs.com

Example of Use

const input = {
  clients: {
    clientA: ["companyA", "companyB"],
    clientB: ["companyB", "companyC"],
    clientC: ["companyC", "companyA"]
  },
  companies: {
    companyA: ["clientA", "clientB"],
    companyB: ["clientA", "clientB"],
    companyC: ["clientA", "clientB"]
  }
};

const meetings = 2;

const output = buildScheduleFromScores(
  input.companies,
  input.clients,
  meetings
);

const outputExpectedToBeSimilarTo = {
  schedule: [
    { companyA: "clientA", companyB: "clientB", companyC: "clientC" },
    { companyB: "clientA", companyC: "clientB", companyA: "clientC" }
  ],
  matching_score_totals: {
    facilitators: { companyA: 5, companyB: 6, companyC: 4 },
    participants: { clientA: 7, clientB: 5, clientC: 3 }
  },
  participant_schedules: {
    clientA: ["companyA", "companyB"],
    clientB: ["companyB", "companyC"],
    clientC: ["companyC", "companyA"]
  },
  facilitator_schedules: {
    companyA: ["clientA", "clientC"],
    companyB: ["clientB", "clientA"],
    companyC: ["clientC", "clientB"]
  }
};

"Expected to Be Similar To"? That Looks Like an Impure Function!!!

Yes, this library uses a MonteCarlo shuffling system to decide which matches get priority ("first dibs") with each schedule timeslot that gets filled with matches.

So what does it optimise for? And How?

See below for 'what' the optimisation process seeks to find, but specifically, the algorithm generates 20 random outcomes and picks the best one.

Explanation of Problem

This problem came about when I was involved in a 'Speed Dating-esque' recruiting event.

One would read about the companies beforehand and make a ranked preference order choice, the companies would do the same for the candidates. Then a schedule was drawn up for 8 possible sessions.

Apparently this process was done manually in a very tedious Excel process, so I decided to build a system that would automatically produce an optimum result.

Naturally, the 'optimum result' may be different depending on your point of view, but one would assume that the following would apply:

  1. 📅 All possible sessions should be filled, even if the matching is not optimal (in this example: the companies are guests, so should therefore see as many job-seekers as they can)
  2. 🗳️ Ranked order preference is respected in that a weight can be given to the ranking, and perhaps for mutual matches.

I'm hoping to build a somewhat generalised system that allows the tweaking of scoring biases and other parameters so that this can act as a library for similar problems.

Code

The code is written in Typescript.
I intend for the outside of the function to not show this, but internally the terms Dogs🐶 and Cats🐱 are used quite a lot.

  • Dogs refers to the Companies in the Problem Example, the main schedule and scores are generated from the perspectives of the dogs, when building the schedule, dogs will always be given a full schedule (if possible)
  • Cats refers to the Job-seekers in the Problem Example. I intend for them to be given a separate 'cat-specific' version of the schedule, but as a result of the scheduling, cats may end up with empty slots in their schedules 🙀

I used these terms because they're shorter, more fun and a little less hard to read than Companies and Job-seekers or Clients 😹

Running Tests Locally

Install Dependancies with yarn Run Tests with yarn test