public ShiftTable GenerateSchedule() { ShiftTable schedule = new ShiftTable(); GenerateSchedule(this.highPriorityOptions, schedule); GenerateSchedule(this.lowPriorityOptions, schedule); return schedule; }
public override void AddOperation(int[] prefixTable) { // Add for first symbol in pattern ShiftTable.Add("0", new Dictionary <char, Move> { { Pattern[0], new Move(nextState: "1", symb: Pattern[0], shift: 1) } }); ShiftTable["0"].Add('$', new Move(nextState: "0", symb: '$', shift: 1)); for (int i = 1; i < prefixTable.Length; i++) { string state = i.ToString(); var patChar = Pattern[i]; if (!ShiftTable.ContainsKey(state)) { if (i == prefixTable.Length - 1) { ShiftTable.Add(state, new Dictionary <char, Move> { { patChar, new Move(nextState: "y", symb: patChar, shift: 1) } }); } else { ShiftTable.Add(state, new Dictionary <char, Move> { { patChar, new Move(nextState: (i + 1).ToString(), symb: patChar, shift: 1) } }); } } ShiftTable[state].Add('$', new Move(nextState: prefixTable[i - 1].ToString(), symb: '$', shift: 0)); } }
private Parser(Lexer lexer, ShiftTable shift, ReduceTable reduce, GotoTable @goto) { this.Lexer = lexer; this.Shift = shift; this.Reduce = reduce; this.Goto = @goto; }
public void GenerateSchedulePriorityTest() { //arrange ShiftTable shifts = new ShiftTable(); Shift shift1 = new Shift("", "", "Sunday", "7", "15", "Sion", "", ""); Shift shift2 = new Shift("", "", "Sunday", "15", "23", "Sion", "", ""); Shift shift3 = new Shift("", "", "Sunday", "23", "7", "Sion", "", ""); shifts.AddShift(shift1); shifts.AddShift(shift2); shifts.AddShift(shift3); ShiftTable options = new ShiftTable(); Shift option1 = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "Low", ""); Shift option2 = new Shift("123456789", "Polishuk", "Sunday", "15", "23", "Sion", "High", ""); Shift option3 = new Shift("123456789", "Polishuk", "Sunday", "23", "7", "Sion", "Low", ""); options.AddShift(option1); options.AddShift(option2); options.AddShift(option3); //act GenerateTable generator = new GenerateTable(options, shifts); ShiftTable schedule = generator.GenerateSchedule(); //assert Assert.AreEqual(schedule.GetAllShifts().Count, 1, "GenerateSchedulePriorityTest error: the number of shift do not mach expectation"); Assert.AreEqual(schedule.optionExists(option2), true, "GenerateSchedulePriorityTest error: the option do not exists"); }
public ShiftTable(ShiftTable other) { this.shiftTable = new List<Shift>(); foreach (Shift sh in other.GetAllShifts()) { this.shiftTable.Add(sh); } }
public GenerateTable(ShiftTable shiftOptionsTable, ShiftTable weeklyShifts) { this.shiftOptionsTable = shiftOptionsTable; this.weeklyShifts = weeklyShifts; this.highPriorityOptions = new ShiftTable(); this.lowPriorityOptions = new ShiftTable(); divideLowOrHigh(); }
private void CreateEntities() { if (_filePaths != null && _filePaths.Count > 0) { List <string> traceNames = new List <string>(); List <string> testProcedureNames = new List <string>(); List <string> shiftTableNames = new List <string>(); List <string> shiftListNames = new List <string>(); foreach (string filePath in _filePaths) { Trace newTrace = new Trace(); TestProcedure newTestProcedure = new TestProcedure(); ShiftTable newShiftTable = new ShiftTable();; ShiftList newShiftList = new ShiftList(); string baseName = GetNameFromPath(filePath); FileContents fileContents = GetFileContents(filePath); List <TraceColumn> columnData = new List <TraceColumn>(); string predictedTraceName = ExtendedEntityManager.PredictEntityName <Trace>(baseName + " Trace", traceNames); string predictedTestProcedureName = ExtendedEntityManager.PredictEntityName <TestProcedure>(baseName + " Test Procedure", testProcedureNames); string predictedShiftTableName = ExtendedEntityManager.PredictEntityName <ShiftTable>(baseName + " Shift Table", shiftTableNames); string predictedShiftListName = ExtendedEntityManager.PredictEntityName <ShiftList>(baseName + " Shift List", shiftListNames); traceNames.Add(predictedTraceName); testProcedureNames.Add(predictedTestProcedureName); shiftTableNames.Add(predictedShiftTableName); shiftListNames.Add(predictedShiftListName); SetTraceData(ref newTrace, ref columnData, fileContents, predictedTraceName); SetTestProcedureData(ref newTestProcedure, predictedTestProcedureName, predictedTraceName); SetShiftTableData(ref newShiftTable, columnData, fileContents, predictedShiftTableName, predictedTraceName); SetShiftListData(ref newShiftList, predictedShiftListName, predictedTestProcedureName, predictedShiftTableName); MEF.EntityManagerView.Traces.Value.Create(ExtendedEntityManager.GetEntityURI <Trace>(), newTrace.Properties); MEF.EntityManagerView.TestProcedures.Value.Create(ExtendedEntityManager.GetEntityURI <TestProcedure>(), newTestProcedure.Properties); MEF.EntityManagerView.ShiftTables.Value.Create(ExtendedEntityManager.GetEntityURI <ShiftTable>(), newShiftTable.Properties); MEF.EntityManagerView.ShiftLists.Value.Create(ExtendedEntityManager.GetEntityURI <ShiftList>(), newShiftList.Properties); ShowDialog(predictedTraceName, predictedTestProcedureName, predictedShiftTableName, predictedShiftListName); //if (filePath == _filePaths.Last()) //{ // Thread newThread = new Thread(x => ShowImportedTrace(predictedTraceName)) { IsBackground = true }; // newThread.Start(); //} } } }
public bool CreateShift(ShiftCreate model) { var entity = new ShiftTable() { Shift = model.Shift }; using (var ctx = new ApplicationDbContext()) { ctx.Shifts.Add(entity); return(ctx.SaveChanges() == 1); } }
} //method #endregion #region Creating parser states private void CreateParserStates() { Data.States.Clear(); _stateHash = new ParserStateTable(); //Create initial state //there is always just one initial production Root' -> Root + LF, and we're interested in LR item at 0 index LR0ItemList itemList = new LR0ItemList(); itemList.Add(Data.AugmentedRoot.Productions[0].LR0Items[0]); Data.InitialState = FindOrCreateState(itemList); //it is actually create Data.InitialState.Items[0].NewLookaheads.Add(Grammar.Eof.Key); //create final state - we need to create it explicitly to assign to _data.FinalState property // final state is based on the same initial production, but different LRItem - the one with dot AFTER the root nonterminal. // it is item at index 1. itemList = new LR0ItemList(); itemList.Add(Data.AugmentedRoot.Productions[0].LR0Items[1]); Data.FinalState = FindOrCreateState(itemList); // Iterate through states (while new ones are created) and create shift transitions and new states for (int index = 0; index < Data.States.Count; index++) { ParserState state = Data.States[index]; AddClosureItems(state); //Get keys of all possible shifts ShiftTable shiftTable = GetStateShifts(state); //Each key in shifts dict is an input element // Value is LR0ItemList of shifted LR0Items for this input element. foreach (string input in shiftTable.Keys) { LR0ItemList shiftedCoreItems = shiftTable[input]; ParserState newState = FindOrCreateState(shiftedCoreItems); state.Actions[input] = new ActionRecord(input, ParserActionType.Shift, newState, null); //link original LRItems in original state to derived LRItems in newState foreach (LR0Item coreItem in shiftedCoreItems) { LRItem fromItem = FindItem(state, coreItem.Production, coreItem.Position - 1); LRItem toItem = FindItem(newState, coreItem.Production, coreItem.Position); if (!fromItem.PropagateTargets.Contains(toItem)) { fromItem.PropagateTargets.Add(toItem); } } //foreach coreItem } //foreach input } //for index } //method
public void divideLowOrHighTest() { //arrange Shift s1 = new Shift("", "", "Sunday", "7", "15", "", "High", ""); Shift s2 = new Shift("", "", "Thursday", "23", "3", "", "Low", ""); ShiftTable t1 = new ShiftTable(); t1.AddShift(s1); t1.AddShift(s2); GenerateTable gen = new GenerateTable(t1, null); ShiftTable high = gen.getHighPriorityOptions(); ShiftTable low = gen.getLowPriorityOptions(); //act bool result_low = low.shiftExists("Thursday", "23", "3"); bool result_high = high.shiftExists("Sunday", "7", "15"); //assert Assert.AreEqual(result_low, false, "divideLowOrHighTest error: the shift is high priotity, expected low"); Assert.AreEqual(result_high, true, "divideLowOrHighTest error: the shift is low priotity, expected high"); }
public override void AddOperation(string state, string character, string[] operation) { var nextState = operation[0]; var symbInstead = operation[1].ToCharArray()[0]; int.TryParse(operation[2], out var shift); Move mv = new Move(nextState: nextState, symb: symbInstead, shift: shift); if (!ShiftTable.ContainsKey(state)) { ShiftTable.Add(state, new Dictionary <char, Move> { { character.ToCharArray()[0], mv } }); } else { ShiftTable[state].Add(character.ToCharArray()[0], mv); } }
}//method private ShiftTable GetStateShifts(ParserState state) { ShiftTable shifts = new ShiftTable(); LR0ItemList list; foreach (LRItem item in state.Items) { BnfTerm term = item.Core.NextElement; if (term == null) { continue; } LR0Item shiftedItem = item.Core.Production.LR0Items[item.Core.Position + 1]; if (!shifts.TryGetValue(term.Key, out list)) { shifts[term.Key] = list = new LR0ItemList(); } list.Add(shiftedItem); } //foreach return(shifts); } //method
private ShiftTable GenerateSchedule(ShiftTable OptionsTable, ShiftTable schedule) { ShiftTable weeklyShifts = new ShiftTable(this.weeklyShifts); GenerateScheduleRandomPass(OptionsTable, weeklyShifts, schedule); bool done = false; bool shiftAdded = false; int optionsNum = OptionsTable.tableSize(); while (!done) { shiftAdded = false; for (int i = 0; i < optionsNum; i++) { Shift option = OptionsTable.getShiftFromTable(i); if (weeklyShifts.shiftExists(option.getDay(), option.getBegin_Time(), option.getEnd_Time())) { if (schedule.optionLegal(option)) { schedule.AddShift(option); OptionsTable.RemoveShift(option); optionsNum--; weeklyShifts.RemoveShift(option.getDay(), option.getBegin_Time(), option.getEnd_Time()); shiftAdded = true; break; } } } // for () if (shiftAdded == false) { done = true; } } return schedule; }
private void CreateParserStates() { Data.States.Clear(); _stateHash = new ParserStateTable(); CreateInitialAndFinalStates(); string augmRootKey = Data.AugmentedRoot.Key; // Iterate through states (while new ones are created) and create shift transitions and new states for (int index = 0; index < Data.States.Count; index++) { ParserState state = Data.States[index]; AddClosureItems(state); //Get keys of all possible shifts ShiftTable shiftTable = GetStateShifts(state); //Each key in shifts dict is an input element // Value is LR0ItemList of shifted LR0Items for this input element. foreach (string input in shiftTable.Keys) { LR0ItemList shiftedCoreItems = shiftTable[input]; ParserState newState = FindOrCreateState(shiftedCoreItems); ActionRecord newAction = new ActionRecord(input, ParserActionType.Shift, newState, null); state.Actions[input] = newAction; //link original LRItems in original state to derived LRItems in newState foreach (LR0Item coreItem in shiftedCoreItems) { LRItem fromItem = FindItem(state, coreItem.Production, coreItem.Position - 1); LRItem toItem = FindItem(newState, coreItem.Production, coreItem.Position); if (!fromItem.PropagateTargets.Contains(toItem)) { fromItem.PropagateTargets.Add(toItem); } //copy hints from core items into the newAction newAction.ShiftItems.Add(fromItem); } //foreach coreItem } //foreach input } //for index Data.FinalState = Data.InitialState.Actions[augmRootKey].NewState; } //method
protected void GenerateScheduleButton_Click(object sender, EventArgs e) { GT = new GenerateTable(shiftOptionsTable, weeklyShiftTable); weeklyShiftTable = GT.GenerateSchedule(); setNames(); foreach (Shift sh in weeklyShiftTable.GetAllShifts()) { string day = sh.getDay().Trim(); string begin = sh.getBegin_Time().Trim(); string name = sh.getName().Trim(); int index = 0; switch (day) { case "Sunday": index = 1; break; case "Monday": index = 2; break; case "Tusday": index = 3; break; case "Wednsday": index = 4; break; case "Thursday": index = 5; break; case "Friday": index = 6; break; case "Saturday": index = 7; break; } int j; int k; bool found = false; for (j = 0; j < WeeklyScheduleGrid.Rows.Count; j++) { if (WeeklyScheduleGrid.Rows[j].Cells[0].Text.Split('-')[0].Trim().Equals(begin)) { while (WeeklyScheduleGrid.Rows[j].Cells[0].Text.Split('-')[0].Trim().Equals(begin) && j < WeeklyScheduleGrid.Rows.Count-1) { if (!selectedIndexes[j, index]) { found = true; break; } j++; } break; } } if (found) { for (k = 0; k < ((DropDownList)WeeklyScheduleGrid.Rows[j].Cells[index].Controls[0]).Items.Count; k++) { if (!((DropDownList)WeeklyScheduleGrid.Rows[j].Cells[index].Controls[0]).Items[k].Text.Trim().Equals(name)) continue; ((DropDownList)WeeklyScheduleGrid.Rows[j].Cells[index].Controls[0]).SelectedIndex = k; ((DropDownList)WeeklyScheduleGrid.Rows[j].Cells[index].Controls[0]).ForeColor = System.Drawing.Color.DeepPink; selectedIndexes[j, index] = true; break; } } } }
protected void SubmitScheduleButton_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(getConnectionString()); string sql = "UPDATE [Shift Schedule] SET [Worker ID] = 'NULL' WHERE [Organization Name] = '" + orgName + "'"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } finally { conn.Close(); } ShiftTable final = new ShiftTable(); conn = new SqlConnection(getConnectionString()); for (int i = 0; i < WeeklyScheduleGrid.Rows.Count; i++) { for (int j = 1; j < WeeklyScheduleGrid.Columns.Count; j++) { String day = WeeklyScheduleGrid.Columns[j].HeaderText.Trim(); String begin = WeeklyScheduleGrid.Rows[i].Cells[0].Text.Split('-')[0].Trim(); String end = WeeklyScheduleGrid.Rows[i].Cells[0].Text.Split('-')[1].Trim(); String name = ((DropDownList) (WeeklyScheduleGrid.Rows[i].Cells[j].Controls[0])).SelectedItem.Text.Trim(); String ID = null; for (int k = 0; k < allWorkersList.listSize(); k++) { if (allWorkersList.getWorkerFromList(k).getFirst_Name().Trim().Equals(name.Split(' ')[0].Trim())) { ID = allWorkersList.getWorkerFromList(k).getWroker_ID(); } } sql = "SET ROWCOUNT 1; UPDATE [Shift Schedule] SET [Worker ID] = '" + ID + "' WHERE [Organization Name] = '" + orgName + "' AND [Day] = '" + day + "' AND [Begin Time] = '" + begin + "' AND [End Time] = '" + end + "' AND [Worker ID] = 'NULL'"; //Shift shift = new Shift(ID, name, day, begin, end, orgName, null, null); //final.AddShift(shift); try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } finally { conn.Close(); } } } Response.Redirect("~/Workers/Manager.aspx"); }
public void OptionLegalNegativeTest_sameHour() { //arrange ShiftTable schedule = new ShiftTable(); Shift shift = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "", ""); schedule.AddShift(shift); Shift option = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "", ""); //act bool result = schedule.optionLegal(option); //assert Assert.AreEqual(result, false, "OptionLegalNegativeTest_sameHour error: the hours are similar"); }
public void OptionLegalTest2_differentID() { //arrange ShiftTable schedule = new ShiftTable(); Shift shift = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "", ""); schedule.AddShift(shift); Shift option = new Shift("111222333", "Polishuk", "Sunday", "7", "15", "Sion", "", ""); //act bool result = schedule.optionLegal(option); //assert Assert.AreEqual(result, true, "OptionLegalTest2_differentID error: the IDs are not similar"); }
public void GenerateScheduleSimpleTest1() { //arrange ShiftTable shifts = new ShiftTable(); Shift shift = new Shift("", "", "Sunday", "7", "15", "Sion", "", ""); shifts.AddShift(shift); ShiftTable options = new ShiftTable(); Shift option = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "", ""); options.AddShift(option); //act GenerateTable generator = new GenerateTable(options, shifts); ShiftTable schedule = generator.GenerateSchedule(); //assert Assert.AreEqual(schedule.GetAllShifts().Count, 1, "GenerateScheduleSimpleTest1 error: the number of shift do not mach expectation"); Assert.AreEqual(schedule.optionExists(option),true, "GenerateScheduleSimpleTest1 error: the option do not exists"); }
public static Parser From(ParserDefinition definition) => new Parser( LexerLoader.From(definition), ShiftTable.From(definition.Table.Shift), ReduceTable.From(definition.Table.Reduce, definition.Grammar.Rules.ToArray()), GotoTable.From(definition.Table.Goto));
private void SetShiftTableData(ref ShiftTable newShiftTable, List <TraceColumn> columnData, FileContents fileContents, string name, string traceName) { ShiftTable templateShiftTableAutomatic = ExtendedEntityManager.DeserializeEntity <ShiftTable>(Properties.Resources.ShiftTableA); ShiftTable templateShiftTableManual = ExtendedEntityManager.DeserializeEntity <ShiftTable>(Properties.Resources.ShiftTableM); int gearIndex = -1; bool isAutomatic = true; for (int i = 0; i < fileContents.NamesSplit.Length; i++) { if (fileContents.NamesSplit[i].Contains("gear")) { gearIndex = i; } } if (gearIndex >= 0) { for (int i = fileContents.DataIndex; i < fileContents.DataLength + fileContents.DataIndex; i++) { string thisGear = fileContents.Lines[i].Split(fileContents.Delimiter)[gearIndex]; if (CaseInsensitiveContains(thisGear, "MANUAL")) { isAutomatic = false; break; } if (CaseInsensitiveContains(thisGear, "AUTOMATIC")) { isAutomatic = true; break; } } } double[] timeData = columnData.FirstOrDefault(x => x.Name == "Time").Data; if (isAutomatic) { double[] speedData = columnData.FirstOrDefault(x => x.Name == "Speed").Data; int start = -1; int end = speedData.Length - 1; for (int i = 0; i < speedData.Length; i++) { if (speedData[i] != 0 && start < 0) { start = i - 1; } if (speedData[i] != 0) { end = i + 1; } } if (start >= 5) { start = start - 5; } else if (start < 0) { start = 0; } if (end > speedData.Length - 1) { end = speedData.Length - 1; } newShiftTable.MaximumGear = templateShiftTableAutomatic.MaximumGear; newShiftTable.TransmissionType = templateShiftTableAutomatic.TransmissionType; newShiftTable.Vectors = templateShiftTableAutomatic.Vectors; newShiftTable.Vectors[0].Data = (new double[] { start, end }).Cast <object>().ToArray(); } else { List <double> time = new List <double>(); List <string> gear = new List <string>(); List <bool> declutch = new List <bool>(); List <string> message = new List <string>(); for (int i = fileContents.DataIndex; i < fileContents.DataLength + fileContents.DataIndex; i++) { string thisGear = fileContents.Lines[i].Split(fileContents.Delimiter)[gearIndex]; if (thisGear != String.Empty) { thisGear = thisGear.Split('-').Last(); if (TypeCast.IsInt(thisGear)) { time.Add(timeData[i - fileContents.DataIndex]); gear.Add(thisGear); declutch.Add(false); message.Add(String.Empty); } } } newShiftTable.MaximumGear = TypeCast.ToInt(gear.Max()); newShiftTable.TransmissionType = templateShiftTableManual.TransmissionType; newShiftTable.Vectors = templateShiftTableManual.Vectors; newShiftTable.Vectors[0].Data = time.Cast <object>().ToArray(); newShiftTable.Vectors[1].Data = gear.Cast <object>().ToArray(); newShiftTable.Vectors[2].Data = declutch.Cast <object>().ToArray(); newShiftTable.Vectors[3].Data = message.Cast <object>().ToArray(); } newShiftTable.TraceName = traceName; newShiftTable.Name = name; }
private void button1_Click(object sender, EventArgs e) { InstanciaWatchComm(); this._watchComm.OpenConnection(); ShiftTableCollection tabela = new ShiftTableCollection(); tabela.Id = 1; ShiftTable shift = new ShiftTable(); shift.Inicio = "0100"; shift.Fim = "0130"; tabela.Add(shift); shift = new ShiftTable(); shift.Inicio = "0200"; shift.Fim = "0330"; tabela.Add(shift); shift = new ShiftTable(); shift.Inicio = "0400"; shift.Fim = "0530"; tabela.Add(shift); shift = new ShiftTable(); shift.Inicio = "0000"; shift.Fim = "0030"; tabela.Add(shift); shift = new ShiftTable(); shift.Inicio = "0100"; shift.Fim = "0130"; tabela.Add(shift); shift = new ShiftTable(); shift.Inicio = "0000"; shift.Fim = "0000"; tabela.Add(shift); this._watchComm.UpdateShiftTable(tabela); //WeeklyJourneyWorking j = new WeeklyJourneyWorking(); //j.Id = 1; //j.Sunday = 0; //j.Monday = 1; //j.Tuesday = 2; //j.Wednesday = 1; //j.Thursday = 2; //j.Friday = 1; //j.Saturday = 0; //j.Holiday = 0; //this._watchComm.setJourneyWorking(j); this._watchComm.CloseConnection(); }
public void shiftExistTest() { //arrange Shift s1 = new Shift("", "", "Sunday", "7", "15", "", "", ""); ShiftTable t1 = new ShiftTable(); t1.AddShift(s1); //act bool result = t1.shiftExists("Sunday", "7", "15"); //assert Assert.AreEqual(result, true, "shiftExistTest error: Shift Does not exist in DB"); }
public ShiftTable Update(ShiftTable entity) { return(_ShiftTableDal.Update(entity)); }
public void Delete(ShiftTable entity) { _ShiftTableDal.Delete(entity); }
public ShiftTable Add(ShiftTable entity) { return(_ShiftTableDal.Add(entity)); }
public void GenerateScheduleTest() { //arrange ShiftTable shifts = new ShiftTable(); Shift shift1 = new Shift("", "", "Sunday", "7", "15", "Sion", "", ""); Shift shift2 = new Shift("", "", "Sunday", "15", "23", "Sion", "", ""); Shift shift3 = new Shift("", "", "Sunday", "23", "7", "Sion", "", ""); Shift shift4 = new Shift("", "", "Monday", "7", "15", "Sion", "", ""); Shift shift5 = new Shift("", "", "Monday", "15", "23", "Sion", "", ""); Shift shift6 = new Shift("", "", "Monday", "23", "7", "Sion", "", ""); Shift shift7 = new Shift("", "", "Tuesday", "7", "15", "Sion", "", ""); Shift shift8 = new Shift("", "", "Tuesday", "15", "23", "Sion", "", ""); Shift shift9 = new Shift("", "", "Tuesday", "23", "7", "Sion", "", ""); Shift shift10 = new Shift("", "", "Wednesday", "7", "15", "Sion", "", ""); Shift shift11 = new Shift("", "", "Wednesday", "15", "23", "Sion", "", ""); Shift shift12 = new Shift("", "", "Wednesday", "23", "7", "Sion", "", ""); shifts.AddShift(shift1); shifts.AddShift(shift2); shifts.AddShift(shift3); shifts.AddShift(shift4); shifts.AddShift(shift5); shifts.AddShift(shift6); shifts.AddShift(shift7); shifts.AddShift(shift8); shifts.AddShift(shift9); shifts.AddShift(shift10); shifts.AddShift(shift11); shifts.AddShift(shift12); ShiftTable options = new ShiftTable(); Shift option1 = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "Low", ""); Shift option2 = new Shift("123456789", "Polishuk", "Sunday", "15", "23", "Sion", "High", ""); Shift option3 = new Shift("123456789", "Polishuk", "Sunday", "23", "7", "Sion", "High", ""); Shift option4 = new Shift("111222333", "Humi", "Sunday", "7", "15", "Sion", "High", ""); Shift option5 = new Shift("111222333", "Humi", "Monday", "7", "15", "Sion", "High", ""); Shift option6 = new Shift("111222333", "Humi", "Tuesday", "7", "15", "Sion", "High", ""); Shift option7 = new Shift("222333444", "Soli", "Wednesday", "7", "23", "Sion", "High", ""); Shift option8 = new Shift("222333444", "Soli", "Wednesday", "22", "7", "Sion", "High", ""); Shift option9 = new Shift("222333444", "Soli", "Wednesday", "7", "7", "Sion", "High", ""); Shift option10 = new Shift("333444555", "Kozo", "Wednesday", "7", "15", "Sion", "High", ""); Shift option11 = new Shift("333444555", "Kozo", "Wednesday", "15", "23", "Sion", "High", ""); Shift option12 = new Shift("333444555", "Kozo", "Wednesday", "23", "7", "Sion", "High", ""); Shift option13 = new Shift("444555666", "Tkuma", "Monday", "7", "15", "Sion", "High", ""); Shift option14 = new Shift("444555666", "Tkuma", "Monday", "15", "23", "Sion", "High", ""); options.AddShift(option1); options.AddShift(option2); options.AddShift(option3); options.AddShift(option4); options.AddShift(option5); options.AddShift(option6); //options.AddShift(option7); options.AddShift(option8); //options.AddShift(option9); options.AddShift(option10); options.AddShift(option11); options.AddShift(option12); options.AddShift(option13); options.AddShift(option14); //act GenerateTable generator = new GenerateTable(options, shifts); ShiftTable schedule = generator.GenerateSchedule(); //assert Assert.AreEqual(schedule.GetAllShifts().Count, 7, "GenerateScheduleTest error: the number of shift do not mach expectation"); Assert.AreEqual(schedule.optionExists(option2), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option4), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option5), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option6), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option10), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option12), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option14), true, "GenerateScheduleTest error: the option do not exists"); }
private void GenerateScheduleRandomPass(ShiftTable OptionsTable, ShiftTable weeklyShifts, ShiftTable schedule) { Random rnd = new Random(); int optionsNum = OptionsTable.tableSize(); while (optionsNum > 0) { int i = rnd.Next(0, optionsNum); Shift option = OptionsTable.getShiftFromTable(i); if (weeklyShifts.shiftExists(option.getDay(), option.getBegin_Time(), option.getEnd_Time())) { if (schedule.optionLegal(option)) { schedule.AddShift(option); weeklyShifts.RemoveShift(option.getDay(), option.getBegin_Time(), option.getEnd_Time()); } } OptionsTable.RemoveShift(option); optionsNum--; } //while (optionsNum > 0)... }
public static Parser From(XDocument definition, Func <Lexer, Lexer> lexicalRules) => new Parser(lexicalRules(LexerLoader.From(definition)), ShiftTable.From(definition), ReduceTable.From(definition), GotoTable.From(definition));
public void ShiftExistNegativeTest() { //arrange Shift s1 = new Shift("", "", "Monday", "7", "15", "", "", ""); ShiftTable t1 = new ShiftTable(); t1.AddShift(s1); //act bool result = t1.shiftExists("Sunday", "7", "15"); //assert Assert.AreEqual(result, false, "ShiftExistNegativeTest: Shift EXIST in DB"); }