DM841 (E23) -  Heuristics and Constraint Programming for
Discrete Optimization

Submission System

The submission of assignments in DM841 is done via IMADA Git Server at https://git.imada.sdu.dk.

Setup

We strongly recommend using a Unix-based operating system (Mac or Linux or WSL) for the assignments. As last resort you can use the Linux machines from the Virtual Computer Lab at IMADA.

Git is a program that manages updates between an online code repository and the copies of the repository, called clones, stored locally on computers. Git is installed in the IMADA Virtual Computer Lab. The instructions given below in this document should be enough for the needs in this course. The tutorials linked below will provide more information than needed in this course. Nevertheless, git is an industry-standard collaboration tool and being able to use it efficiently is an asset.

If you decide to use your own computer and git is not already installed on your computer, you can download it at http://git-scm.com/downloads (or use the installation procedure of your specific system). If you have never used git, you might want to read a few of the following resources.

There are many websites for hosting online git repositories. IMADA has its own server for hosting git repositories https://git.imada.sdu.dk. While not needed for submitting your code, you can login to the webpage using your university account name and the same password as you use for reading your mail or logging into blackboard. Choose as authentication source “SDU”.

  1. Clone your existing repository.

    Usually, you have to create a repository. However, we already created a repository for each student of DM841. You will not have to create any repositories, but only clone it.

  2. Connect your folder to the new repository. In a shell application (Terminal on Linux or Mac, or Git Bash (https://gitforwindows.org/ on Windows), enter the following commands (we will use the student with the username “username” as example, of course you have to change this).

    Navigate to the folder where you want to store your files

    $ cd /path/to/folder  # cd means 'change directory'.
    

    Make sure you are in the right place.

    $ pwd                 # pwd means 'print working directory'.
    /path/to/folder
    
    # Clone the repository we provided
    
    $ git clone https://git.imada.sdu.dk/DM841_23/Repo_<username>.git
    
    Cloning into 'username-repo'...
    Username for 'https://git.imada.sdu.dk': username
    Password for 'https://username@git.imada.sdu.dk': ********
    remote: Counting objects: 48, done.
    remote: Compressing objects: 100% (44/44), done.
    remote: Total 48 (delta 16), reused 0 (delta 0)
    Unpacking objects: 100% (48/48), done.
    $ ls 
    Repo_<username>
    
    $ cd Repo_<username>
    $ ls -rtl
    total 8
    drwxrwxr-x 4 marco marco 4096 Oct  1 09:31 asg1
    -rw-rw-r-- 1 marco marco   31 Oct  1 09:32 README.md
    
    # Record your credentials (has to be done once only).
    $ git config --local user.name "Firstname Surname"
    $ git config --local user.email "username@student.sdu.dk"
    

Using Git

Git manages the history of a file system through commits, or checkpoints. Use to see the files that have been changed since the last commit. These changes are then moved to the (local) staging area (a list of files for the next commit) git add <filename>. Record then the changes to the staging area with git commit -m "<message>".

All these commands are done within a “clone” of the repository, which is stored somewhere on a computer. This repository must be manually synchronized with the remote repository server via two other git commands: git pull, to pull updates from the web to the computer; and git push, to push updates from the computer to the git server.

For the assignments in DM841 you will have first to add your files to the staging area, then it has to be commited and then it has to be pushed to the remote server.

Command Explanation
git status Display the staging area and untracked changes.
git pull Pull changes from the online repository.
git push Push changes to the online repository.
git add <files> Add a file or files to the staging area.
git commit -m "<message>" Save the changes in the staging area with a given message.

Some additional commands you might need in DM841:

Command Explanation
git add <files> Add all modified, tracked files to the staging area.
git checkout -- <filename> Revert changes to an unstaged file since the last commit.
git reset HEAD -- <filename> Remove a file from the staging area.
git diff <filename> See the changes to an unstaged file since the last commit.
git diff --cached <filename> See the changes to a staged file since the last commit.
git config --local <option> Record your credentials (user.name, user.email, etc.).

Example Work Session

Cloning and giving details on your name and email has only to be done once. The below work session assumes this has been done already.

Short version:

$ cd ~/Courses/DM841/Assignments/Repo_<username>
$ git pull                                         # Pull updates.

# Make changes to a file (in this example src/onlytesting.py)

# Record the changes in git.
$ git add asg1/problem-1/src/preprocess.py                   # Track changes.
$ git commit -m "Made some changes."                         # Commit changes.
$ git push                                                   # Push updates.

Long version:

# Navigate to the clone of the repository.
$ cd ~/Courses/DM841/Assignments/Repo_<username>

# Pull any updates from the online repository, if they exist.

$ git pull

remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From https://git.imada.sdu.dk/DM841_22/Repo_<username>
   6dde06d..e24cee5  master     -> origin/master
Updating 6dde06d..e24cee5
Fast-forward
 asg1/problem-1/src/preprocess.py/ | 33 +++++----------------------------
 1 file changed, 5 insertions(+), 28 deletions(-)

 
# Work on the assignment. For example, modify asg1/problem-1/src/preprocessing.py

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   asg1/problem-1/src/preprocessing.py

no changes added to commit (use "git add" and/or "git commit -a")

$ git add asg1/problem-1/src/preprocessing.py
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   asg1/problem-1/src/preprocessing.py

# Commit the changes to the repository with an informative message.
$ git commit -m "Made some changes"
[master 72a5ab3] Made some changes
 1 file changed, 1 insertion(+)
<<[master fed9b34] Made some changes
 1 file changed, 10 insertion(+) 1 deletion(-)>>

# Push the changes to the online repository.
$ git push
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 373 bytes | 373.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To https://git.imada.sdu.dk/DM841_22/Repo_<username>.git
   e24cee5..72a5ab3  master -> master


# The changes have been saved and the online repository updated.
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

File Organization

Use the following structure and names for your repository, where problem is the problem solved:

Repo_march$ tree
.
├── asg1
│   ├── problem-0
│   │   ├── data
│   │   ├── doc
│   │   └── src
│   │       └── run.sh
│   └── README.md
└── README.md

9 directories, 4 files

The report goes in the directory doc/

The file run.sh could look as follows:

#!/bin/bash

if [ "$#" -ne 1 ]; then
    echo "Instance name missing"
    exit 1
fi

python3 prepare_data.py $1   # preparing the instance in dzn format
minizinc -s model.mzn data.dzn > output.sln
python3 postprocess.py output.sln    # gatering the output and rewriting 

Note, not all the steps above might be necessary for your case.

The output of run.sh must be the one and only that is specified in the problem description. Make sure run.sh is in executable mode:

ls -rtl asg1/problem/src/
total 4
-rwxrwxr-x 1 marco marco 201 Sep 20 20:02 run.sh