Flight Scheduling Problem

##Row

Flight Scheduling Problem

Row

Problem Background: Flight Scheduling Problem

The Warehouse Location Problem:

asfefEUIhioeAWHOOOOOOOOOOOOOOOOIvczjknkjvnLVHNLIhdoiFSjhfpDIOjklcvxnlkn wahehf ——————————————

Staff Scheduling Problem

Row

Hospital Staff Scheduling Problem

Row

Problem Background: Hospital Staff Scheduling Problem

The mTSP vehicle routing problem:

A hospital manager should plan the working timetable for the hospital staff. Determine the minimum weekly cost associated with the staff of this hospital if - The daily working time is structured in 3 shifts. - In every shift there should be at least 1 physician, 2 (male) nurses, and 3 assistants. - The maximum total number of employees needed on every shift is 10. - The salaries are: $50/shift for a physician, $20/shift for a nurse, and $10/shift for an assistant. - The total number of employees is: 15 physicians, 36 nurses, and 49 assistants. - Each employee should rest during at least two consecutive shifts.
Formulate a mixed integer programming problem
Decision Variables: \(\small x_{ijk}\): Binary variable indicating whether employee \(\small i\) works in shift \(\small j\) on day \(\small k\), where: \(\small i\) represents each employee (physician, male nurse, assistant), \(\small j\) represents each shift (1st shift, 2nd shift, 3rd shift), \(\small k\) represents each day of the week (Monday, Tuesday, …, Sunday).
Objective Function: \[\small \min \sum_{i}\sum_{j}\sum_{k} (50x_{ijk} + 20x_{ijk} + 10x_{ijk})\] Subject to:
1. Each shift should have at least 1 physician, 2 male nurses, and 3 assistants:
\(\small \sum_{i}x_{ijk} \geq 1\)  for physicians,
\(\small \sum_{i}x_{ijk} \geq 2\)  for male nurses,
\(\small \sum_{i}x_{ijk} \geq 3\)  for assistants,
2. The maximum total number of employees on every shift is 10:
\(\small \sum_{i}x_{ijk} \leq 10\)  ,
3. Each employee should rest during at least two consecutive shifts:
\(\small x_{ijk} + x_{i(j+1)k} + x_{i(j+2)k} \leq 1\)
for all employees and days of the week

---
title: "Scheduling with MILP"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    social: menu
    source_code: embed
    theme: simplex
    css: www/css/custom.css
runtime: shiny
editor_options: 
  markdown: 
    wrap: 72
---

```{r setup, global, include=FALSE}
rm(list = ls())
library(shiny)
library(magrittr)
library(leaflet) # devtools::install_github('rstudio/leaflet')
library(highcharter) # devtools::install_github('jbkunst/highcharter')
library(plotly) # devtools::install_github('ropensci/plotly')
library(ggplot2) # devtools::install_github('hadley/ggplot2')
library(sp)
library(dplyr)
library(flexdashboard) # devtools::install_github('rstudio/flexdashboard')
library(rgeos)
library(mapproj)
library(maptools)
library(readr)
library(ggthemes)
library(knitr)
library(viridis)
library(formattable)
library(ggrepel)
library(ompr)
library(ompr.roi)
library(ROI.plugin.glpk)
source(file = "helper.R")
```

# Flight Scheduling Problem {data-vertical_layout="scroll"}

## Sidebar5 {.sidebar}

```{r}
hr()
  strong("Parameters")
  hr()
  br()
  sliderInput(inputId = "num_flights", label = "Number of Flights:",min = 1, max = 100, value = 60)
  sliderInput(inputId = "runway_capacity[1]", label = "R1 Capacity:", min = 1, max = 50, value = 30)
  sliderInput(inputId = "runway_capacity[2]", label = "R2 Capacity:", min = 1, max = 100,value =15)
  sliderInput(inputId = "runway_capacity[3]", label = "R3 Capacity:", min = 1, max = 100,value =17)
  br()
  actionButton(inputId = "solve_it5", label = "Schedule flights")
  hr()
  
```

## ##Row {data-width="1100"}

### Flight Scheduling Problem

```{r}



renderTable({
  input$solve_it5 
  if(input$solve_it5 == 0){num_flights <- input$num_flights
        runway_capacity <- c(input$`runway_capacity[1]`, input$`runway_capacity[2]`, input$`runway_capacity[3]`)
        # print(runway_capacity)  # Debugging statement
        return(solve_flight_scheduling(num_flights, runway_capacity))
  } else {
  isolate({
    withProgress(message = 'Scheduling in Progress', value = 0, {
      incProgress(0.5)
      if(input$solve_it5 > 0){
        num_flights <- input$num_flights
        runway_capacity <- c(input$`runway_capacity[1]`, input$`runway_capacity[2]`, input$`runway_capacity[3]`)
        # print(runway_capacity)  # Debugging statement
        return(solve_flight_scheduling(num_flights, runway_capacity))
      }
    })
  })
  }
})

  
```

## Row {data-width="1100"}

### Problem Background: Flight Scheduling Problem

<h4>The Warehouse Location Problem:</h4>

asfefEUIhioeAWHOOOOOOOOOOOOOOOOIvczjknkjvnLVHNLIhdoiFSjhfpDIOjklcvxnlkn
wahehf ------------------------------------------

# Staff Scheduling Problem {data-vertical_layout="scroll"}

## Sidebar2 {.sidebar}

```{r}
hr()
strong("Application Parameters")
hr()
br()
sliderInput(inputId = "num_physicians", label = "Number of Physicians:",min = 1, max = 30, value = 10)
sliderInput(inputId = "num_nurses", label = "Number of Nurses:", min = 1, max = 50, value = 30)
sliderInput(inputId = "num_assistants", label = "Number of Assistants:", min = 1, max = 100,value =60)
    br()
    actionButton(inputId = "solve_it4", label = "Schedule staff")
    hr()

```

## Row {data-width="1100"}

### Hospital Staff Scheduling Problem

```{r}
renderTable({
  input$solve_it4
  if(input$solve_it4 == 0){
     num_physicians <- input$num_physicians
        num_nurses <-  input$num_nurses
        num_assistants <- input$num_assistants
        optimize_result <- optimize_staffing(num_physicians, num_nurses, num_assistants)
        # print(runway_capacity)  # Debugging statement
        return(optimize_result)
  } else {
  isolate({
    withProgress(message = 'Scheduling in Progress', value = 0, {
      incProgress(0.5)
      if(input$solve_it4 > 0){
        num_physicians <- input$num_physicians
        num_nurses <-  input$num_nurses
        num_assistants <- input$num_assistants
        optimize_result <- optimize_staffing(num_physicians, num_nurses, num_assistants)
        
        return(optimize_result)
      }
    })
  })
  }
})

```

## Row {data-width="1100"}

### Problem Background: Hospital Staff Scheduling Problem

<h4>The mTSP vehicle routing problem:</h4>

<font size="2"> A hospital manager should plan the working timetable for
the hospital staff. Determine the minimum weekly cost associated with
the staff of this hospital if</font> - <font size="2">The daily working
time is structured in 3 shifts.</font> - <font size="2">In every shift
there should be at least 1 physician, 2 (male) nurses, and 3
assistants.</font> - <font size="2">The maximum total number of
employees needed on every shift is 10.</font> - <font size="2">The
salaries are: \$50/shift for a physician, \$20/shift for a nurse, and
\$10/shift for an assistant.</font> - <font size="2">The total number of
employees is: 15 physicians, 36 nurses, and 49 assistants.</font> -
<font size="2">Each employee should rest during at least two consecutive
shifts.<br> </font> <font size="2"> Formulate a mixed integer
programming problem <br> Decision Variables: $\small x_{ijk}$: Binary
variable indicating whether employee $\small i$ works in shift
$\small j$ on day $\small k$, where: $\small i$ represents each employee
(physician, male nurse, assistant), $\small j$ represents each shift
(1st shift, 2nd shift, 3rd shift), $\small k$ represents each day of the
week (Monday, Tuesday, ..., Sunday).<br> Objective Function:
$$\small \min \sum_{i}\sum_{j}\sum_{k} (50x_{ijk} + 20x_{ijk} + 10x_{ijk})$$
Subject to:<br> 1. Each shift should have at least 1 physician, 2 male
nurses, and 3 assistants:<br> $\small \sum_{i}x_{ijk} \geq 1$ B for
physicians,<br> $\small \sum_{i}x_{ijk} \geq 2$ B for male nurses,<br>
$\small \sum_{i}x_{ijk} \geq 3$ B for assistants,<br> 2. The maximum
total number of employees on every shift is 10:<br>
$\small \sum_{i}x_{ijk} \leq 10$ B ,<br> 3. Each employee should rest
during at least two consecutive shifts:<br>
$\small x_{ijk} + x_{i(j+1)k} + x_{i(j+2)k} \leq 1$<br> for all
employees and days of the week