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

Fix bug in custom constraint parser, minor improvements #40

Merged
merged 24 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b641830
Fix bug, minor improvements
prateekkumarweb Nov 9, 2018
0b0cbf7
Merge branch 'master' into bugfix
sukrutrao Nov 10, 2018
0a1b7b4
Use logger to indicate completed parsing
sukrutrao Nov 10, 2018
03dc6cc
Reset variables in custom_parser: constraint_expr
prateekkumarweb Nov 11, 2018
0a29355
Merge branch 'bugfix' of github.com:GoodDeeds/Timetabler into bugfix
prateekkumarweb Nov 11, 2018
c863bb7
yaml-cpp: Do not build unnecessary tools
prateekkumarweb Nov 11, 2018
402552b
snap: Fix issue with accessing home folder
prateekkumarweb Nov 11, 2018
c9c1f13
snap: Fix deprecated warning
prateekkumarweb Nov 11, 2018
d7cd72a
constraint_adder: unbundle some of the predefined constraints
prateekkumarweb Nov 13, 2018
f2d3859
Wrap custom parser grammar in namespace
prateekkumarweb Nov 13, 2018
e226f3f
doxygen: generate docs for custom constraint grammar
prateekkumarweb Nov 15, 2018
fdc5d46
doxygen: Add documentation of some of the undocumented functions
prateekkumarweb Nov 15, 2018
5737962
Predefined Constraint: Add high level vars for each course
prateekkumarweb Nov 17, 2018
c8b1d77
cmake: Add -Wpedantic flag
prateekkumarweb Nov 26, 2018
2885211
Change MinorType to enum class (also fixes isMinor bug)
prateekkumarweb Nov 29, 2018
2fec7b7
Parser: CSV Parser program Core/Elective/No
prateekkumarweb Nov 29, 2018
86478f6
Generate version number from git
prateekkumarweb Dec 12, 2018
9c552fe
Run gen_version.sh inside cmake
prateekkumarweb Dec 12, 2018
6440035
gen_version.sh: Disable print of version
prateekkumarweb Dec 12, 2018
045526a
snap: Fix version number in snap
prateekkumarweb Dec 12, 2018
8321fde
install_dependencies.sh: Update folder names to not contain version
prateekkumarweb Dec 13, 2018
0843e50
snap: Speed up dependency installation, fix version
prateekkumarweb Dec 13, 2018
855c74e
Add snapstore button in README
prateekkumarweb Dec 13, 2018
f3f0d6f
README: Update prerequisite for building timetabler
prateekkumarweb Dec 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ dependencies

*.swp

# Version
include/version.h
TimetablerVersion.cmake

# Snap
*.snap
snap/.snapcraft
*.xdelta*
parts
prime
stage
.idea
cmake-build-debug
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ include(TimetablerVersion.cmake)

set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-parentheses -Wno-misleading-indentation")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-parentheses -Wno-misleading-indentation -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DTIMETABLERDEBUG")

set(OPEN_WBO_PATH "${CMAKE_SOURCE_DIR}/dependencies/open-wbo" CACHE PATH "Open-WBO path")
set(YAML_CPP_PATH "${CMAKE_SOURCE_DIR}/dependencies/yaml-cpp-yaml-cpp-0.6.2" CACHE PATH "YAML CPP path")
set(YAML_CPP_PATH "${CMAKE_SOURCE_DIR}/dependencies/yaml-cpp" CACHE PATH "YAML CPP path")
set(CSVPARSER_PATH "${CMAKE_SOURCE_DIR}/dependencies/CSVparser" CACHE PATH "CSVParser path")
set(PEGTL_PATH "${CMAKE_SOURCE_DIR}/dependencies/PEGTL-2.7.0" CACHE PATH "PEGTL path")
set(PEGTL_PATH "${CMAKE_SOURCE_DIR}/dependencies/PEGTL" CACHE PATH "PEGTL path")
set(ENABLE_TESTS "OFF" CACHE BOOL "Enable Google tests")
set(GTEST_PATH "${CMAKE_SOURCE_DIR}/dependencies/googletest-release-1.8.1" CACHE PATH "GTest path")

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This project generates a timetable given a set of inputs and constraints. It enc

## Installation

[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-black.svg)](https://snapcraft.io/timetabler)

**For Ubuntu/Debian users:** Download the deb for the latest version of Timetabler from [here](https://github.com/GoodDeeds/Timetabler/releases) and install it.

To build the project from source follow the steps below.
Expand All @@ -19,6 +21,8 @@ To build the project from source follow the steps below.
This project requires following tools to build.
* cmake (version 3.10 or higher)
* g++ or any other C++ compiler with C++11 support
* `zlib` (On ubuntu: `sudo apt install zlib1g-dev`)
* `libgmp` (On ubuntu: `sudo apt install libgmp-dev`)

### Dependencies

Expand Down
6 changes: 0 additions & 6 deletions TimetablerVersion.cmake

This file was deleted.

10 changes: 7 additions & 3 deletions docs/Doxyfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
PROJECT_NAME = "Timetabler"
OUTPUT_DIRECTORY = build
INPUT = .. README.md
EXCLUDE = ../tests ../src/custom_parser.cpp
INPUT = .. ../README.md
EXCLUDE = ../tests ../dependencies ../snap ../parts ../prime ../stage ../build ../docs
RECURSIVE = YES
QUIET = YES
GENERATE_HTML = YES
GENERATE_XML = NO
GENERATE_LATEX = NO
USE_MDFILE_AS_MAINPAGE = README.md
SOURCE_BROWSER = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
USE_MDFILE_AS_MAINPAGE = ../README.md

15 changes: 15 additions & 0 deletions gen_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
Timetabler_VERSION=$(git describe --always --tags)
if [ -z "$Timetabler_VERSION" ]
then
# Update the below line after every release
Timetabler_VERSION="v0.3.0"
fi
VERSION_INCLUDE_STR="#ifndef __TIMETABLER_VERSION__\n#define __TIMETABLER_VERSION__ \"${Timetabler_VERSION}\"\n#endif"
if [ "$2" == "1" ]
then
echo ${Timetabler_VERSION:1}
else
echo -e $VERSION_INCLUDE_STR > $1/include/version.h
echo "set (Timetabler_VERSION \"${Timetabler_VERSION:1}\")" > $1/TimetablerVersion.cmake
fi
15 changes: 8 additions & 7 deletions include/constraint_adder.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@ class ConstraintAdder {
*/
Timetabler *timetabler;
Clauses fieldSingleValueAtATime(FieldType);
Clauses exactlyOneFieldValuePerCourse(FieldType);
std::vector<Clauses> exactlyOneFieldValuePerCourse(FieldType);
Clauses instructorSingleCourseAtATime();
Clauses classroomSingleCourseAtATime();
Clauses programSingleCoreCourseAtATime();
Clauses minorInMinorTime();
Clauses coreInMorningTime();
Clauses electiveInNonMorningTime();
Clauses existingAssignmentClauses();
Clauses programAtMostOneOfCoreOrElective();
std::vector<Clauses> minorInMinorTime();
std::vector<Clauses> coreInMorningTime();
std::vector<Clauses> electiveInNonMorningTime();
// Clauses existingAssignmentClauses();
std::vector<Clauses> programAtMostOneOfCoreOrElective();

public:
ConstraintAdder(ConstraintEncoder *, Timetabler *);
void addConstraints();
void addSingleConstraint(PredefinedClauses, const Clauses &);
void addSingleConstraint(PredefinedClauses, const Clauses &,
const int course);
};

#endif
8 changes: 0 additions & 8 deletions include/custom_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ struct Object {
Object();
};

/**
* @brief Parses custom constraints given in a file and adds them to the
* solver.
*
* @param[in] file The file containing the constraints
* @param constraintEncoder The ConstraintEncoder object
* @param timetabler The Timetabler object
*/
void parseCustomConstraints(std::string file,
ConstraintEncoder *constraintEncoder,
Timetabler *timetabler);
Expand Down
13 changes: 12 additions & 1 deletion include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef DATA_H
#define DATA_H

#include <map>
#include <string>
#include <vector>
#include "core/Solver.h"
Expand Down Expand Up @@ -78,7 +79,13 @@ class Data {
* can make the necessary changes.
*/
std::vector<std::vector<Var>> highLevelVars;
std::vector<Var> predefinedConstraintVars;
/**
* Stores the high level variables associated with the predefined constraints.
*/
std::vector<std::vector<Var>> predefinedConstraintVars;
/**
* Stores the high level variables associated with the custom constraints.
*/
std::vector<Var> customConstraintVars;
/**
* Stores the existing assignments for every Course and
Expand Down Expand Up @@ -115,6 +122,10 @@ class Data {
* or to disable certain constraints.
*/
std::vector<int> predefinedClausesWeights;
/**
* Stores the course with the associated custom constraint.
*/
std::map<int, unsigned> customMap;
Data();
};

Expand Down
8 changes: 4 additions & 4 deletions include/fields/course.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class Course {
* the index of the type in the list of possible isMinor
* values.
*/
int isMinor;
MinorType isMinor;

int classroom = -1;

int slot = -1;

public:
Course(std::string, unsigned, int, int, int);
Course(std::string, unsigned, int, int, int, std::vector<int>);
Course(std::string, unsigned, int, int, MinorType);
Course(std::string, unsigned, int, int, MinorType, std::vector<int>);
void setPrograms(std::vector<int>);
void addProgram(int);
void addClassroom(int);
Expand All @@ -64,7 +64,7 @@ class Course {
int getInstructor();
std::vector<int> getPrograms();
int getSegment();
int getIsMinor();
MinorType getIsMinor();
int getClassroom();
int getSlot();
unsigned getClassSize();
Expand Down
2 changes: 1 addition & 1 deletion include/fields/is_minor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* value under this enum would be isMinorCourse, and otherwise,
* it would be isNotMinorCourse.
*/
enum MinorType {
enum class MinorType {
/**
* Value when the Course is a minor course
*/
Expand Down
6 changes: 3 additions & 3 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ enum FieldType { instructor, segment, isMinor, program, classroom, slot };
* @brief Enum that represents all the predefined constraints.
*/
enum PredefinedClauses {
instructorSingleCourseAtATime,
classroomSingleCourseAtATime,
programSingleCoreCourseAtATime,
instructorSingleCourseAtATime, // 1
classroomSingleCourseAtATime, // 1
programSingleCoreCourseAtATime, // 1
minorInMinorTime,
exactlyOneSlotPerCourse,
exactlyOneInstructorPerCourse,
Expand Down
5 changes: 5 additions & 0 deletions include/global_vars.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/** @file */

#ifndef GLOBAL_VARS_H
#define GLOBAL_VARS_H

#include "timetabler.h"

/**
* Timetabler variable
*/
extern Timetabler *timetabler;

#endif
3 changes: 2 additions & 1 deletion include/timetabler.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Timetabler {
void addClauses(const std::vector<CClause> &, int);
void addClauses(const Clauses &, int);
bool checkAllTrue(const std::vector<Var> &);
bool checkAllTrue(const std::vector<std::vector<Var>> &);
bool isVarTrue(const Var &);
SolverStatus solve();
Var newVar();
Expand All @@ -74,7 +75,7 @@ class Timetabler {
void displayTimeTable();
void displayUnsatisfiedOutputReasons();
void addHighLevelClauses();
void addHighLevelConstraintClauses(PredefinedClauses);
void addHighLevelConstraintClauses(PredefinedClauses, const int course);
void addHighLevelCustomConstraintClauses(int, int);
void writeOutput(std::string);
void addExistingAssignments();
Expand Down
3 changes: 0 additions & 3 deletions include/version.h

This file was deleted.

13 changes: 9 additions & 4 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ if [ "$PARALLEL" = "-j" ] ; then
echo "Running make jobs in parallel"
fi

echo "Generating version files..."
./gen_version.sh .

mkdir -p dependencies
cd dependencies

Expand All @@ -45,16 +48,17 @@ LIB=open-wbo make libr $PARALLEL
cd ..

echo "Getting YAML-CPP..."
if [ ! -d yaml-cpp-yaml-cpp-$YAML_CPP_VERSION ] ; then
if [ ! -d yaml-cpp ] ; then
wget -O yaml-cpp.tar.gz https://github.com/jbeder/yaml-cpp/archive/yaml-cpp-$YAML_CPP_VERSION.tar.gz
tar -xf yaml-cpp.tar.gz
rm yaml-cpp.tar.gz
mv yaml-cpp-yaml-cpp-$YAML_CPP_VERSION yaml-cpp
fi
cd yaml-cpp-yaml-cpp-$YAML_CPP_VERSION
cd yaml-cpp
mkdir -p build
cd build
echo "Building YAML-CPP..."
cmake ..
cmake -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DYAML_CPP_BUILD_CONTRIB=OFF ..
make $PARALLEL
cd ../..

Expand All @@ -67,10 +71,11 @@ git checkout $CSVPARSER_COMMIT
cd ..

echo "Getting PEGTL..."
if [ ! -d PEGTL-$PEGTL_VERSION ] ; then
if [ ! -d PEGTL ] ; then
wget -O pegtl.tar.gz https://github.com/taocpp/PEGTL/archive/$PEGTL_VERSION.tar.gz
tar -xf pegtl.tar.gz
rm pegtl.tar.gz
mv PEGTL-$PEGTL_VERSION PEGTL
fi

if [ "$ENABLE_TESTS" = "1" ]; then
Expand Down
1 change: 0 additions & 1 deletion snap/.gitignore

This file was deleted.

22 changes: 14 additions & 8 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
name: timetabler
version: "0.3.0+git"
version: git
version-script:
./gen_version.sh . 1
summary: Timetable scheduling software using MaxSAT solver.
description: |
A highly customizable timetabling software for educational institutions
that encodes timetabling constraints as a SAT formula and solves them
using a MaxSAT solver.
type: app
# Set grade to devel in other commits and stable in release commits
grade: devel
grade: stable
confinement: strict

apps:
timetabler:
command: timetabler
plugs: [home]

parts:
timetabler:
plugin: cmake
prepare: bash ../src/install_dependencies.sh
override-build: |
cd ../src/
bash install_dependencies.sh --parallel
cd -
snapcraftctl build
configflags:
- -DOPEN_WBO_PATH=dependencies/open-wbo
- -DYAML_CPP_PATH=dependencies/yaml-cpp-yaml-cpp-0.6.2
- -DCSVPARSER_PATH=dependencies/CSVparser
- -DPEGTL_PATH=dependencies/PEGTL-2.7.0
- -DOPEN_WBO_PATH=../src/dependencies/open-wbo
- -DYAML_CPP_PATH=../src/dependencies/yaml-cpp
- -DCSVPARSER_PATH=../src/dependencies/CSVparser
- -DPEGTL_PATH=../src/dependencies/PEGTL
Loading