//function that returns a list that contains the Available for action AGVs private List <GridPos> NotTrappedVehicles(List <GridPos> Vehicles, GridPos End) { //Vehicles is a list with all the AGVs that are inserted in the Grid by the user int list_index = 0; int trapped_index = 0; bool removed; //First, we must assume that ALL the AGVs are trapped and cannot move (trapped means they are prevented from reaching the END block) for (int i = 0; i < trappedStatus.Length; i++) { trappedStatus[i] = true; } do { removed = false; jumpParam.Reset(Vehicles[list_index], End); //we use the A* setting function and pass the //initial start point of every AGV and the final destination (end block) if (AStarFinder.FindPath(jumpParam, nud_weight.Value).Count == 0) //if the number of JumpPoints that is calculated is 0 (zero) { //it means that there was no path found Vehicles.Remove(Vehicles[list_index]); //we removed, from the returning list, the AGV for which there was no path found AGVs.Remove(AGVs[list_index]); //we remove the corresponding AGV from the public list that contains all the AGVs which will participate in the simulation removed = true; } else { trappedStatus[trapped_index] = false; //since it's not trapped, we switch its state to false } if (!removed) { AGVs[list_index].ID = list_index; list_index++; } trapped_index++; }while (list_index < Vehicles.Count); //the above process will be repeated until all elements of the incoming List are parsed. return(Vehicles); //list with NOT TRAPPED AGVs' starting points (trapped AGVs have been removed) //the point of this function is to consider every AGV as trap and then find out which AGVs //eventually, are not trapped and keep ONLY those ones. }
public void LoadConfig(string path) { StreamReader sr = new StreamReader(path); var config = (JObject)JsonConvert.DeserializeObject(sr.ReadToEnd()); sr.Close(); JToken token; if (config.TryGetValue("AGVConfig", out token)) { ISerialize serialize = new ProtoClass(); foreach (JObject t in token.Values()) { try { IPort port = new TcpPort(t.Value <string>("port")); //var test = $"HuiJinYun.Domain.Entity.Device.{t.Value<string>("type")}AGV<TState, TPosition>"; Type type = Type.GetType($"HuiJinYun.Domain.Entity.Device.{t.Value<string>("type")}AGV`2"); type = type.MakeGenericType(typeof(eHuiJinYunAGVState), typeof(eHuiJinYunStagePosition)); object[] @params = new object[] { port, serialize }; @params = @params.Concat(buildParams(type, t.Value <JObject>("options"))).ToArray <object>(); var agv = (IAGV <eHuiJinYunAGVState, eHuiJinYunStagePosition>)Activator.CreateInstance(type, @params); AGVs.Add(agv); } catch { continue; } } } if (config.TryGetValue("DeviceConfig", out token)) { ISerialize serialize = new ProtoClass(); foreach (JObject t in token.Values()) { try { var port = PortFactory.NewPort(t.Value <string>("port")); Type type = Type.GetType($"HuiJinYun.Domain.Entity.Device.{t.Value<string>("type")}Device"); var device = (PlcDeviceBase)Activator.CreateInstance(type, port, serialize); Devices.Add(((JProperty)t.Parent).Name, device); } catch (Exception ex) { continue; } } } if (config.TryGetValue("StageConfig", out token)) { foreach (var t in token.Values()) { try { List <IDevice> deviceList = new List <IDevice>(); foreach (var d in t["Device"].Values <string>()) { deviceList.Add(Devices[d]); } Type type = Type.GetType($"HuiJinYun.Domain.Entity.{((JProperty)t.Parent).Name}Stage"); var stage = (IProductionStage)Activator.CreateInstance(type, deviceList.ToArray()); Stages.Add(stage); } catch (Exception ex) { continue; } } } object[] buildParams(Type type, JObject joParams) { if (null == joParams) { return(new object[0]); } else { object[] @params = new object[joParams.Count]; List <JProperty> jpParams = new List <JProperty>(joParams.Properties()); for (var i = 0; i < jpParams.Count; i++) { @params[i] = jpParams[i].Value.Value <string>(); } return(@params); } } }