示例#1
0
 protected virtual void OnOpRepaired(OpRepairedEventArgs e)
 {
     OpRepaired?.Invoke(this, e);
 }
示例#2
0
        private void OpRepaired(object sender, OpRepairedEventArgs e)
        {
            int i = Activities.IndexOf((Unit_Op)sender);
            //If no faults in OPs, then restart all machines
            bool no_faults = true;

            foreach (Unit_Op op in OPs)
            {
                if (op.Faulted)
                {
                    no_faults = false;
                }
            }
            if (no_faults)
            {
                foreach (Unit_Op op in OPs)
                {
                    if (!op.Running)
                    {
                        op.Running = true;
                    }
                }
                return;
            }

            //Get buffer indexes and group unit ops, set unit ops in groups to running if buffers are in good states
            List <int> buffer_indexes = new List <int>();

            foreach (IOperations iop in Activities)
            {
                if (iop.IsBuffer())
                {
                    Buffer buff = (Buffer)iop;
                    buffer_indexes.Add(Activities.IndexOf(iop));
                }
            }

            List <List <Unit_Op> > op_groups = new List <List <Unit_Op> >();

            bool[] group_ready = new bool[buffer_indexes.Count + 1];
            int    last_buff   = 0;

            for (int j = 0; j < buffer_indexes.Count; j++)
            {
                op_groups.Add(new List <Unit_Op>());
                group_ready[j] = true;
                for (int m = last_buff; m < buffer_indexes[j]; m++)
                {
                    Unit_Op op = (Unit_Op)Activities[m];
                    op_groups[j].Add(op);
                    if (op.Faulted)
                    {
                        group_ready[j] = false;
                    }
                    if (j + 1 == buffer_indexes.Count)
                    {
                        op_groups.Add(new List <Unit_Op>());
                        group_ready[j + 1] = true;
                        for (int n = buffer_indexes[j] + 1; n < Activities.Count; n++)
                        {
                            Unit_Op _op = (Unit_Op)Activities[n];
                            op_groups[j + 1].Add(_op);
                            if (_op.Faulted)
                            {
                                group_ready[j + 1] = false;
                            }
                        }
                        break;
                    }
                }
                last_buff = buffer_indexes[j] + 1;
            }

            int?prod_to_run_begins_at    = null;
            int?downstream_space_ends_at = null;
            int k = 0;

            for (int j = 0; j < group_ready.Length; j++)
            {
                //If this group is ready, check for start conditions
                if (group_ready[j])
                {
                    //If first group on line, then set product availability to 0 (line entrance, no upstream buffer)
                    if (j == 0)
                    {
                        prod_to_run_begins_at = 0;
                    }

                    //Until a group is not ready, continue looping and evaluating where product may fill and is available
                    k = j;
                    while (group_ready[k])
                    {
                        if (!prod_to_run_begins_at.HasValue)
                        {
                            Buffer buff = (Buffer)Activities[buffer_indexes[k - 1]];
                            if (!buff.Buffer_Empty)
                            {
                                prod_to_run_begins_at = k;
                            }
                        }

                        if (k + 1 == group_ready.Length)
                        {
                            downstream_space_ends_at = k;
                        }
                        else if (!((Buffer)Activities[buffer_indexes[k]]).Buffer_Full)
                        {
                            downstream_space_ends_at = k;
                        }
                        k++;

                        if (k == group_ready.Length)
                        {
                            break;
                        }
                    }
                }
                if (prod_to_run_begins_at.HasValue && downstream_space_ends_at.HasValue)
                {
                    for (int l = (int)prod_to_run_begins_at; l <= downstream_space_ends_at; l++)
                    {
                        foreach (Unit_Op op in op_groups[l])
                        {
                            op.Running = true;
                        }
                    }
                }

                prod_to_run_begins_at    = null;
                downstream_space_ends_at = null;
            }
        }