[R] Monte carlo help
mathsohard
ksayho at gmail.com
Mon Mar 7 00:42:11 CET 2011
Hello, I am currently doing my project and I need some help.
I am trying to schedule tutors for a study room where students come in and
out for helps. My goal is to schedule the tutors to maximally accomodate to
the flow of students that need help with math so that each tutor is given an
appropriate(also consecutive) hours of schedule. I am using monte carlo
simulation for this, however I have difficulties setting up constraints and
variables. First I made some R codes concerning this to first get
appropriate number of tutors for each hours (as the place opens from 8 am to
7 pm). I researched how many people are coming in and out for a week and I
am just going to use those numbers for my probability for each hours
a <- 0; # probability of students coming in
tutors <- 2; # number of tutors
cat("week", "weekday", "hours", "tutors", "students", " solved", "
unsolved","\n");
total_stud <- 0; #total student number
total_solved <- 0; #total number of questions answered
total_unsolved <- 0; #total number of questions unanswered
for (week in 1:3) {
for (weekday in 1:5) {
for (hours in 1:11) {
solved <- 0;
unsolved <- 0;
if (hours == 1) {
a <- 1/5;
} else if (hours == 2) {
a <- 1/6;
} else if (hours == 3) {
a <- 1/7;
} else if (hours == 4) {
a <- 1/7;
} else if (hours == 5) {
a <- 1/7;
} else if (hours == 6) {
a <- 1/7;
} else if (hours == 7) {
a <- 1/7;
} else if (hours == 8) {
a <- 1/7;
} else if (hours == 9) {
a <- 1/7;
} else if (hours == 10) {
a <- 1/7;
} else if (hours == 11) {
a <- 1/7;
}
random_num <- runif(1);
if (random_num < a)
students <- 1
else
students <- 0;
if (students == 1) {
if (tutors > 0) {
solved <- solved+1;
tutors <- tutors-1;
}else{
unsolved = unsolved+1;
}
}
total_stud <- total_stud + students;
total_solved <- total_solved + solved;
total_unsolved <- total_unsolved + unsolved;
cat(week,"\t", weekday,"\t", hours, "\t", tutors,"\t", students,"\t",
solved,"\t", unsolved,"\n"); # display results for
} # end loop on each hours
} # endloop on weekday
} # loop on week
# output total statistics now....
cat("\n totals over entire simulation:\n\n")
cat(" students solved unsolved\n")
cat("\t",total_stud,"\t",total_solved,"\t", total_unsolved,"\n")
Please how can I improve this I am completely stuck and how Can i get
organized result, I tried to use cat however it seems not working, lost.....
please help !!!
--
View this message in context: http://r.789695.n4.nabble.com/Monte-carlo-help-tp3338196p3338196.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list