Example #1
0
        void experiment_ScenarioEnded(object sender, ScenarioEndedEventArgs e)
        {
            IExperiment experiment = (IExperiment)sender;
            // get response value
            _cr = new ConfigResult();
            foreach (IExperimentResponse response in experiment.Responses)
            {
                double responseValue = 0.0;
                if (e.Scenario.GetResponseValue(response, ref responseValue))
                {
                    //e.Scenario.Name - 001
                    //response.Name - AvgTimeInSystem
                    //responseValue.ToString() - Value
                    //System.Diagnostics.Debug.WriteLine("{0} {1,-40} {2,-4}", e.Scenario.Name, response.Name, responseValue.ToString());

                    if (response.Name == "AvgNumberinWaitingRoom") { _cr.avgnumberinwaitingroom = responseValue; }
                    if (response.Name == "AvgWaitingTime") { _cr.avgwaitingtime = responseValue; }
                    if (response.Name == "WaitingTimeForER") { _cr.examroom_wt = responseValue; }
                    if (response.Name == "WaitingTimeForTrauma") { _cr.trauma_wt = responseValue; }
                    if (response.Name == "WaitingTimeForFT") { _cr.fasttrack_wt = responseValue; }
                    if (response.Name == "ExamRoomUtilization") { _cr.examroomu = responseValue; }
                    if (response.Name == "TraumaUtilization") { _cr.traumau = responseValue; }
                    if (response.Name == "FastTrackUtilization") { _cr.fasttracku = responseValue; }
                    if (response.Name == "RapidAdmissionUnitUtilization") { _cr.rapidadmissionu = responseValue; }
                    if (response.Name == "BehavioralUtilization") { _cr.behavioru = responseValue; }
                    if (response.Name == "ObservationUtilization") { _cr.observationu = responseValue; }
                    if (response.Name == "TotalTimeOfStay") { _cr.timeinsystem = responseValue; }
                    if (response.Name == "LWBS") { _cr.LWBS = responseValue; }
                    if (response.Name == "TotalVisits") { _cr.totalVisits = Convert.ToInt32(responseValue); }
                    //only if we want to send back individual responses
                    Response r = new Response(response.Name, responseValue);
                    currentResponses.Add(r);
                }
            }

            calculateCosts(_c,_cr, _type);

            _completed = true;
            //System.Diagnostics.Debug.WriteLine("Scenario Ended");
        }
Example #2
0
        public List<ConfigResult> queryResults(Configuration c = null)
        {
            SQLiteConnection conn = new SQLiteConnection("Data Source = configs.db");
            conn.Open();
            SQLiteCommand cmd;
            if(c == null)
                cmd = new SQLiteCommand("select * from Results order by TotalCost", conn);
            else
            {
                String sql = "select * from Results where ";
                for (int i = 0; i < 6; i++)
                {
                    if (i < 5)
                        sql += c.rooms[i].name.Replace(" ", "") + " = " + c.rooms[i].num + " and ";
                    else
                        sql += c.rooms[i].name.Replace(" ", "") + " = " + c.rooms[i].num;
                }
                cmd = new SQLiteCommand(sql, conn);

            }
            SQLiteDataReader dr = cmd.ExecuteReader();
            List<ConfigResult> list = new List<ConfigResult>();
            while (dr.Read())
            {
                int examRoom = Convert.ToInt32(dr["ExamRoom"]);
                int trauma = Convert.ToInt32(dr["Trauma"]);
                int fastTrack = Convert.ToInt32(dr["FastTrack"]);
                int rapidAdmission = Convert.ToInt32(dr["RapidAdmission"]);
                int behavioral = Convert.ToInt32(dr["Behavioral"]);
                int observation = Convert.ToInt32(dr["Observation"]);
                double timeinsystem = Convert.ToDouble(dr["TimeInSystem"]);
                double avgwaitingtime = Convert.ToDouble(dr["AvgWaitingTime"]);
                double avgnumberinwaitingroom = Convert.ToDouble(dr["AvgNumberinWaitingRoom"]);
                double traumau = Convert.ToDouble(dr["TraumaUtilization"]);
                double examroomu = Convert.ToDouble(dr["ExamRoomUtilization"]);
                double fastttracku = Convert.ToDouble(dr["FastTrackUtilization"]);
                double rapidadmissionu = Convert.ToDouble(dr["RapidAdmissionUnitUtilization"]);
                double behavioru = Convert.ToDouble(dr["BehaviorUtilization"]);
                double observationu = Convert.ToDouble(dr["ObservationUtilization"]);
                double LWBS = Convert.ToDouble(dr["LWBS"]);
                double initialCost = Convert.ToDouble(dr["InitialCost"]);
                double annualCost = Convert.ToDouble(dr["AnnualCost"]);
                double totalCost = Convert.ToDouble(dr["TotalCost"]);
                int totalVisits = Convert.ToInt32(dr["TotalVisits"]);
                double examroom_wt = Convert.ToDouble(dr["ExamRoomWaitingTime"]);
                double trauma_wt = Convert.ToDouble(dr["TraumaWaitingTime"]);
                double fasttrack_wt = Convert.ToDouble(dr["FastTrackWaitingTime"]);
                ConfigResult cr = new ConfigResult(examRoom, trauma, fastTrack, rapidAdmission, behavioral, observation, timeinsystem, avgwaitingtime, avgnumberinwaitingroom, traumau, examroomu, fastttracku, rapidadmissionu, behavioru, observationu, LWBS, initialCost, annualCost, totalCost,totalVisits,examroom_wt,trauma_wt,fasttrack_wt);
                list.Add(cr);
            }
            return list;
        }
Example #3
0
        private void calculateCosts(Configuration c, ConfigResult cr, string type)
        {
            double interestRate = c.costInfo.other[0].value;
            double growthRate = c.costInfo.other[1].value;
            double yearsToCompletion = c.costInfo.other[2].value;
            double yearsAhead = c.costInfo.other[3].value;

            double[] utilResponses = new double[6];
            utilResponses[0] = _cr.examroomu;
            utilResponses[1] = _cr.traumau;
            utilResponses[2] = _cr.fasttracku;
            utilResponses[3] = _cr.rapidadmissionu;
            utilResponses[4] = _cr.behavioru;
            utilResponses[5] = _cr.observationu;

            HoptServer.Models.CalculateCosts calc = new HoptServer.Models.CalculateCosts();
            _initial = calc.initialCost(c.costInfo, c.rooms, type);
            _annual = calc.annualCost(c.costInfo, c.rooms, c.acuityInfo, c.arrivalInfo, c.daysToRun, utilResponses, _cr.LWBS, type);
            _total = calc.costAtConstructionStart(c.costInfo, c.rooms, c.acuityInfo, c.arrivalInfo, interestRate, growthRate, yearsToCompletion, yearsAhead, c.daysToRun, utilResponses, _cr.LWBS, type);
            _responses = calc.getUtilizationAndLWBS(c.rooms);
            _cr.initialCost = _initial;
            _cr.annualCost = _annual;
            _cr.totalCost = _total;
            //System.Diagnostics.Debug.WriteLine("Fixed Cost: " + _initial);
            //System.Diagnostics.Debug.WriteLine("Variable Cost: " + _annual);
            //System.Diagnostics.Debug.WriteLine("Total Cost in 10 yrs: " + _total);

            //SQLiteConnection conn = new SQLiteConnection("Data Source = configs.db");
            //conn.Open();
            //string sql = "Update Results set InitialCost = " + _initial + ", AnnualCost = " + _annual + ", TotalCost = " + _total;
            //sql += " where ";
            //for (int i = 0; i < c.rooms.Length; i++)
            //{
            //    if (i < 5)
            //        sql += c.rooms[i].name.Replace(" ", "") + " = " + c.rooms[i].num + " and ";
            //    else
            //        sql += c.rooms[i].name.Replace(" ", "") + " = " + c.rooms[i].num;
            //}
            //SQLiteCommand command = new SQLiteCommand(sql, conn);
            //command.ExecuteNonQuery();
        }
Example #4
0
        //public double getUtilizationForRoomType(string name, ConfigResult cr) {
        //    double utilization = 0.0;
        //    if (name == "examroomu")
        //    {
        //        utilization = cr.examroomu;
        //    }
        //    else if (name == "traumau")
        //    {
        //        utilization = cr.traumau;
        //    }
        //    else if (name == "fasttracku")
        //    {
        //        utilization = cr.fasttracku;
        //    }
        //    else if (name == "rapidadmissionu")
        //    {
        //        utilization = cr.rapidadmissionu;
        //    }
        //    else if (name == "observationu")
        //    {
        //        utilization = cr.observationu;
        //    }
        //    else if (name == "behavioru")
        //    {
        //        utilization = cr.behavioru;
        //    }
        //    return utilization;
        //}
        //public void findRoomConstraintsForRoomType(Constraint[] cs, int num, string name, Configuration c, ConfigResult cr, Configuration c2, ConfigResult cr2)
        //{
        //    // Check Utilization
        //    cs[num].responseName = name;
        //    // If less than 50%, don't even both trying to add
        //    double utilization = getUtilizationForRoomType(name, cr);
        //    //System.Diagnostics.Debug.WriteLine(name + " " + utilization);
        //    if (utilization < 50)
        //    {
        //        cs[num].lowerBound = c.rooms[num].num;
        //        cs[num].upperBound = c.rooms[num].num;
        //    }
        //    else
        //    {
        //        cs[num].lowerBound = c.rooms[num].num;
        //        // looping until util 50%
        //        for (int i = c.rooms[num].num + 4; i < 1000; i += 4)
        //        {
        //            c2 = (Configuration) c.Clone();
        //            c2.rooms[num].num = i;
        //            cr2 = s.RunOpt(c2);
        //            double utilization2 = getUtilizationForRoomType(name, cr2);
        //            //System.Diagnostics.Debug.WriteLine(name + " " + utilization);
        //            if (utilization2 < 50)
        //            {
        //                cs[num].upperBound = i;
        //                break;
        //            }
        //        }
        //    }
        //}
        public void FindOpt(int num, ref Configuration c, ref ConfigResult cr, ref Boolean canIterate)
        {
            ConfigResult cr2;
            Boolean costDecreases = true;
            while (costDecreases == true)
            {
                System.Diagnostics.Debug.WriteLine("New: " + c.rooms[num].optNum + " Old:" + c.rooms[num].originalNum);
                if (c.rooms[num].optNum <= c.rooms[num].originalNum)
                {
                    c.rooms[num].optNum = c.rooms[num].originalNum;
                    costDecreases = false;
                }
                else
                {
                    double interestRate = c.costInfo.other[0].value;
                    double growthRate = c.costInfo.other[1].value;
                    double yearsToCompletion = c.costInfo.other[2].value;
                    double yearsAhead = c.costInfo.other[3].value;

                    double[] utilResponses = new double[6];
                    utilResponses[0] = cr.examroomu;
                    utilResponses[1] = cr.traumau;
                    utilResponses[2] = cr.fasttracku;
                    utilResponses[3] = cr.rapidadmissionu;
                    utilResponses[4] = cr.behavioru;
                    utilResponses[5] = cr.observationu;
                    HoptServer.Models.CalculateCosts calc = new HoptServer.Models.CalculateCosts();
                    string type = "opt";
                    double oldTotalCost = calc.costAtConstructionStart(c.costInfo, c.rooms, c.acuityInfo, c.arrivalInfo, interestRate, growthRate, yearsToCompletion, yearsAhead, c.daysToRun, utilResponses, cr.LWBS, type);
                    cr2 = (ConfigResult)cr.Clone();
                    c.rooms[num].optNum = c.rooms[num].optNum - 1;
                    System.Diagnostics.Debug.WriteLine("Num rooms: " + c.rooms[num].optNum);
                    cr = s.RunOptNew(c,"opt");

                    System.Diagnostics.Debug.WriteLine("Cost: " + s.getTotalCost() + " " + oldTotalCost);
                    Boolean waitingTime = false;
                    //if (c.rooms[0].included == true) {
                    //    waitingTime = waitingTime || cr.examroom_wt > Convert.ToDouble(c.serviceInfo[0].averageRoomTime);
                    //}
                    //if (c.rooms[1].included == true)
                    //{
                    //    waitingTime = waitingTime || cr.trauma_wt > Convert.ToDouble(c.serviceInfo[1].averageRoomTime);
                    //}
                    //if (c.rooms[2].included == true)
                    //{
                    //    waitingTime = waitingTime || cr.fasttrack_wt > Convert.ToDouble(c.serviceInfo[2].averageRoomTime);
                    //}

                    if (s.getTotalCost() > oldTotalCost || waitingTime == true)
                    {
                        costDecreases = false;
                        c.rooms[num].optNum = c.rooms[num].optNum + 1;
                        cr = (ConfigResult) cr2.Clone();
                    }
                    else
                    {
                        canIterate = true;
                    }
                }
            }
        }