Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] NUSMods Optimizer Prototyping #3296

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from

Conversation

frizensami
Copy link

@frizensami frizensami commented Jun 28, 2021

Context

This WIP PR accompanies the discussions on timetable optimization in #3294.

This PR is for rapid prototyping based on the discussions in the issue + auto deployment to Vercel so that changes can be viewed easily.

Implementation

Note: won't try to fulfil npm run ci warnings/errors mostly for now, will implement functionality first

Discussion points

Some discussion points in no particular order:

  • Main entry point to view optimizer (on the main timetable? separate tab? Former seems quite natural.)
    • Should we modify the main timetable and then give users an option to undo to their initial timetable?
  • Where to display constraints? (Just below modules? Popup/Modal? Not immediately in favour of the popup/modal idea since users perhaps can't change constraints + rerun optimizer quickly)
  • How to guide users on how to use constraints?
  • When should we download the ~ 4 MB solver file? During initial NUSMods page load? Or only when the user starts to use the optimizer?
  • In the future, we might have competing optimization constraints, e.g., (a) maximize my free days but (b) give me lunch hours. This might require users to rank or weight their optimization preferences.

Implementation Plan

After further discussion I can update this PR with an implementation plan. Minimally, this needs:

  • Constraints UI / UX
  • Integrating the Z3 worker, wasm file, and wrappers
  • Classes and utils to translate from an NUSMods timetable --> SMTLIB2 --> solver results --> back to a timetable
  • (In progress) Non-UI/UX cleanup
  • Properly publish the smtlib-ext library so we can stop the github reference
  • A LOT of tests
  • Vendor types for Z3 and smtlib?
    Of the above, the Constraints UI will need the most work. The latter two already have been somewhat implemented in the standalone NUS Timetable Optimizer.

Translation utils:

  • (In progress) NUSMods timetable --> Optimizer's GenericTimetable
  • Z3 results --> list of changes to make to the existing timetable
  • More to be updated

Known bugs / limitations

  • Expects only normal semesters (1, 2)
  • Assumes normal weeks array (NumericWeeks: number[]) and not WeekRange (strange week ranges)

Things to test

  • Lesson types with spaces need to be processed before going into the solver as variable names. Solver varnames cannot have spaaces.

Current changes

These are just to indicate the idea, please no punterino on the UI :D

  1. Implements a "Show/Hide Optimizer" button on the main timetable UI
    image
  2. Showing the optimizer (for now) displays a set of constraints below the timetable
    image

Other Information

This is more or less the first time I'm using React, and I'm not much of a front-end designer (clearly, haha), so I'll try to keep up! 🙂

* Optimizer button next to Exam Calendar
* Placeholder component with a hr and text
* Redux actions and reducers for maintaining optimizer state across tab changes

Redux state is necessary since we want optimizer settings to be maintained even if user navigates to check other modules
@vercel
Copy link

vercel bot commented Jun 28, 2021

@frizensami is attempting to deploy a commit to the NUSMods Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jun 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

nusmods-export – ./export

🔍 Inspect: https://vercel.com/nusmodifications/nusmods-export/F6wr24apyRy6p4hGMibo8L7cBmFq
✅ Preview: https://nusmods-export-git-fork-frizensami-optimizer-nusmodifications.vercel.app

nusmods-website – ./website

🔍 Inspect: https://vercel.com/nusmodifications/nusmods-website/GcyXY4La9EfW3SnYE5Xdw1zfScDP
✅ Preview: https://nusmods-website-git-fork-frizensami-optimizer-nusmodifications.vercel.app

@codecov
Copy link

codecov bot commented Jun 28, 2021

Codecov Report

Merging #3296 (978acb1) into master (0fb2e47) will increase coverage by 1.29%.
The diff coverage is 67.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3296      +/-   ##
==========================================
+ Coverage   53.16%   54.46%   +1.29%     
==========================================
  Files         270      280      +10     
  Lines        5720     6274     +554     
  Branches     1323     1404      +81     
==========================================
+ Hits         3041     3417     +376     
- Misses       2679     2857     +178     
Impacted Files Coverage Δ
website/src/reducers/index.ts 100.00% <ø> (ø)
website/src/types/reducers.ts 100.00% <ø> (ø)
website/src/utils/timetables.ts 93.50% <ø> (ø)
...rc/views/optimizer/TimetableOptimizerContainer.tsx 3.33% <3.33%> (ø)
...bsite/src/views/optimizer/OptimizerConstraints.tsx 11.11% <11.11%> (ø)
website/src/actions/optimizer.ts 33.33% <33.33%> (ø)
website/src/utils/optimizer/converter.ts 44.30% <44.30%> (ø)
website/src/views/timetable/TimetableContent.tsx 54.46% <66.66%> (+0.33%) ⬆️
website/src/reducers/optimizer.ts 71.42% <71.42%> (ø)
website/src/types/optimizer.ts 100.00% <100.00%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0fb2e47...978acb1. Read the comment docs.

@frizensami frizensami changed the title NUSMods Optimizer Prototyping [WIP] NUSMods Optimizer Prototyping Jun 28, 2021
website/package.json Outdated Show resolved Hide resolved
website/src/types/optimizer.ts Show resolved Hide resolved
/**
* Defs for communicating between Optimizer <-> WebWorker <-> WASM wrapper
* */
export enum Z3MessageKind {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something stopping us from using numbers instead? Iirc, when we pass things to wasm, it is more efficient.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Z3 message is maybe a misnomer, it's a message for the Z3 Worker. I'll rename it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little easier to debug with string enums, so if it's not a performance concern (very few messages are sent generally), I think the string enum might be ok.

This is a library we control, provides an API for us to create SMT-LIB 2.0 code to pass to Z3.
Fork of https://github.com/stanford-oval/node-smtlib + additional APIs for our use case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants