library(grouper)
library(ompr)
library(ompr.roi)
#library(ROI.plugin.gurobi)
library(ROI.plugin.glpk)
This vignette illustrates the use of the package on simple datasets, for which the optimal solutions are apparent from inspection.
The first dataset comprises just 4 students. Here is what it looks like. The name of this dataset indicates that it is for the diversity-based-assignment (dba) model and that it consists of the group composition (gc) information.
It is intuitive that an assignment into two groups of size two, based on the diversity of majors alone, should assign students 1 and 2 into the first group and the remaining two students into another group.
The corresponding YAML dba_gc_ex001.yml
file for this
exercise consists of the following lines:
n_topics: 2
R: 1
nmin: 2
nmax: 2
rmin: 1
rmax: 1
To run the assignment using only the primary major (ignoring the skill), we can use the following commands. We can use either the gurobi solver, or the glpk solver for this example. Both are equally fast.
# indicate appropriate columns using integer ids.
df_ex001_list <- extract_student_info(dba_gc_ex001, "diversity",
demographic_cols = 2, skills = 3,
self_formed_groups = 4)
yaml_ex001_list <- extract_params_yaml(system.file("extdata",
"dba_params_ex001.yml",
package = "grouper"),
"diversity")
m1 <- prepare_model(df_ex001_list, yaml_ex001_list, assignment="diversity",
w1=1.0, w2=0.0)
#result3 <- solve_model(m1, with_ROI(solver="gurobi"))
result3 <- solve_model(m1, with_ROI(solver="glpk"))
assign_groups(result3, assignment = "diversity", dframe=dba_gc_ex001,
group_names="groups")
#> topic rep group id major skill
#> 1 1 1 2 2 A 1
#> 2 1 1 4 4 B 3
#> 3 2 1 1 1 A 1
#> 4 2 1 3 3 B 3
We can see that students 1 and 2 have been assigned to topic 1, repetition 1. Students 3 and 4 have been assigned to topic 2, repetition 1.
# indicate appropriate columns using integer ids.
df_ex001_list <- extract_student_info(dba_gc_ex001, "diversity",
demographic_cols = 2, skills = 3,
self_formed_groups = 4)
yaml_ex001_list <- extract_params_yaml(system.file("extdata",
"dba_params_ex001.yml",
package = "grouper"),
"diversity")
m1a <- prepare_model(df_ex001_list, yaml_ex001_list, assignment="diversity",
w1=0.0, w2=1.0)
#result3 <- solve_model(m1a, with_ROI(solver="gurobi"))
result3 <- solve_model(m1a, with_ROI(solver="glpk"))
assign_groups(result3, assignment = "diversity", dframe=dba_gc_ex001,
group_names="groups")
#> topic rep group id major skill
#> 1 1 1 2 2 A 1
#> 2 1 1 3 3 B 3
#> 3 2 1 1 1 A 1
#> 4 2 1 4 4 B 3
get_solution(result3, smin)
#> smin
#> 4
get_solution(result3, smax)
#> smax
#> 4
We can see that students 1 and 2 have been assigned to topic 1, repetition 1. Students 3 and 4 have been assigned to topic 2, repetition 1.
The second datasets comprises 8 students. Here is a listing of the dataset:
Each student is in a self-formed group of size 2, indicated via the
grouping
column. Suppose that, for this set of students,
the instructor wishes to assign students into two topics, with each
topic having two sub-groups. This requires the preference matrix to have
4 columns - one for each topic-subgroup combination. Remember that the
ordering of topics/subtopics should be:
T1S1, T2S1, T1S2, T2S2
There should be 4 rows in the preference matrix - one for each self-formed group.
pba_prefmat_ex002
#> col1 col2 col3 col4
#> [1,] 4 3 2 1
#> [2,] 3 4 2 1
#> [3,] 1 2 4 3
#> [4,] 1 2 3 4
It is possible to assign each self-formed group to its optimal choice of topic-subtopic combination. In our solution, we should see that group 1 is assigned to subtopic 1 of topic 1, group 2 is assigned to sub-topic 1 of topic 2, and so on.
df_ex002_list <- extract_student_info(pba_gc_ex002, "preference",
self_formed_groups = 2,
pref_mat = pba_prefmat_ex002)
yaml_ex002_list <- extract_params_yaml(system.file("extdata",
"pba_params_ex002.yml",
package = "grouper"),
"preference")
m2 <- prepare_model(df_ex002_list, yaml_ex002_list, "preference")
#result2 <- solve_model(m2, with_ROI(solver="gurobi"))
result2 <- solve_model(m2, with_ROI(solver="glpk"))
assign_groups(result2, assignment = "preference",
dframe=pba_gc_ex002, yaml_ex002_list,
group_names="grouping")
#> topic2 subtopic rep group size
#> 1 1 1 1 1 2
#> 2 2 1 1 2 2
#> 3 1 2 1 3 2
#> 4 2 2 1 4 2