/**
         * returns a provider, which can be a stockExchangeProvider, if article can be fulfilled by stock, else
         * a productionOrder/purchaseOrderPart
         */
        private Provider CreateStockExchangeProvider(M_Article article, DueTime dueTime,
                                                     Quantity demandedQuantity)
        {
            if (demandedQuantity == null || demandedQuantity.GetValue() == null)
            {
                throw new MrpRunException("Quantity is not set.");
            }
            M_Stock         stock         = _dbMasterDataCache.M_StockGetByArticleId(article.GetId());
            T_StockExchange stockExchange = new T_StockExchange();

            stockExchange.StockExchangeType = StockExchangeType.Provider;
            stockExchange.Quantity          = demandedQuantity.GetValue().GetValueOrDefault();
            stockExchange.State             = State.Created;

            stockExchange.Stock          = stock;
            stockExchange.StockId        = stock.Id;
            stockExchange.RequiredOnTime = dueTime.GetValue();
            stockExchange.ExchangeType   = ExchangeType.Withdrawal;
            StockExchangeProvider stockExchangeProvider = new StockExchangeProvider(stockExchange);

            return(stockExchangeProvider);
        }
コード例 #2
0
        /// <summary>
        /// Updates the DB with the information in the Reocurring Chore targeted by the method
        /// </summary>
        public void Update()
        {
            //Creates queries that updates the concrete_chore and chore entries with this chore's ID
            string query = string.Format("UPDATE Reoccurring_chore SET " +
                                         "due_time='{0}' WHERE chore_id={1}",
                                         DueTime.ToString("T"), ID);
            string query2 = string.Format("UPDATE chore SET " +
                                          "child_id={0}, name='{1}', description='{2}', points={3} WHERE chore_id={4}",
                                          Assignment, Name, Description, Points, ID);
            string query3 = string.Format("DELETE FROM days WHERE reo_id=" +
                                          "(SELECT reo_id FROM Reoccurring_chore WHERE chore_id={0})", ID);
            string query4;

            //Executes the 3 first queries
            SqlCommand command = new SqlCommand(query, Functions.DatabaseFunctions.DatabaseConnection);

            Functions.DatabaseFunctions.DatabaseConnection.Open();
            command.ExecuteNonQuery();
            command = new SqlCommand(query2, Functions.DatabaseFunctions.DatabaseConnection);
            command.ExecuteNonQuery();
            command = new SqlCommand(query3, Functions.DatabaseFunctions.DatabaseConnection);
            command.ExecuteNonQuery();

            //Creates and executes an insert query for each day in the list
            foreach (string day in Days)
            {
                //Creates the query string
                query4 = string.Format("INSERT INTO [days] (reo_id, day) VALUES " +
                                       "((SELECT reo_id FROM Reoccurring_chore WHERE chore_id={0}), '{1}')", ID, day);

                //Executes the query
                command = new SqlCommand(query4, Functions.DatabaseFunctions.DatabaseConnection);
                command.ExecuteNonQuery();
            }

            //Closes connection to DB
            Functions.DatabaseFunctions.DatabaseConnection.Close();
        }
        public static Demand CreateStockExchangeStockDemand(Id articleId, DueTime dueTime, Quantity quantity)
        {
            if (quantity == null || quantity.GetValue() == null)
            {
                throw new MrpRunException("Quantity is not set.");
            }
            IDbMasterDataCache dbMasterDataCache =
                ZppConfiguration.CacheManager.GetMasterDataCache();
            T_StockExchange stockExchange = new T_StockExchange();

            stockExchange.StockExchangeType = StockExchangeType.Demand;
            stockExchange.Quantity          = quantity.GetValue().GetValueOrDefault();
            stockExchange.State             = State.Created;
            M_Stock stock = dbMasterDataCache.M_StockGetByArticleId(articleId);

            stockExchange.Stock          = stock;
            stockExchange.StockId        = stock.Id;
            stockExchange.RequiredOnTime = dueTime.GetValue();
            stockExchange.ExchangeType   = ExchangeType.Insert;
            StockExchangeDemand stockExchangeDemand =
                new StockExchangeDemand(stockExchange);

            return(stockExchangeDemand);
        }
コード例 #4
0
        public void ScheduleWithGifflerThompsonAsZaepfel(IPriorityRule priorityRule,
                                                         IDirectedGraph <INode> operationGraph)
        {
            Dictionary <Id, List <Resource> > resourcesByResourceCapabilityId =
                new Dictionary <Id, List <Resource> >();

            foreach (var resourceCapability in _dbMasterDataCache.M_ResourceCapabilityGetAll())
            {
                resourcesByResourceCapabilityId.Add(resourceCapability.GetId(),
                                                    ZppConfiguration.CacheManager.GetAggregator()
                                                    .GetResourcesByResourceCapabilityId(resourceCapability.GetId()));
            }

            // set correct idleStartTimes in resources from operations of last cycle(s)
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            IDbTransactionData dbTransactionDataArchive =
                ZppConfiguration.CacheManager.GetDbTransactionDataArchive();

            // TODO: This is a huge performance impact, consider having an T_Resource with new field IdleStartTime
            // so the following collection iterations can be skipped (Archive operations can be huge)
            CorrectIdleStartTimesOfMachines(dbTransactionData.ProductionOrderOperationGetAll(),
                                            resourcesByResourceCapabilityId);
            CorrectIdleStartTimesOfMachines(dbTransactionDataArchive.ProductionOrderOperationGetAll(),
                                            resourcesByResourceCapabilityId);


            /*
             * S: Menge der aktuell einplanbaren Arbeitsvorgänge
             * a: Menge der technologisch an erster Stelle eines Fertigungsauftrags stehenden Arbeitsvorgänge
             * N(o): Menge der technologisch direkt nachfolgenden Arbeitsoperationen von Arbeitsoperation o
             * M(o): Maschine auf der die Arbeitsoperation o durchgeführt wird
             * K: Konfliktmenge (die auf einer bestimmten Maschine gleichzeitig einplanbaren Arbeitsvorgänge)
             * p(o): Bearbeitungszeit von Arbeitsoperation o (=Duration)
             * t(o): Startzeit der Operation o (=Start)
             * d(o): Fertigstellungszeitpunkt von Arbeitsoperation o (=End)
             * d_min: Minimum der Fertigstellungszeitpunkte
             * o_min: Operation mit minimalem Fertigstellungszeitpunkt
             * o1: beliebige Operation aus K (o_dach bei Zäpfel)
             */
            IStackSet <ProductionOrderOperation> S = new StackSet <ProductionOrderOperation>();

            // Bestimme initiale Menge: S = a
            S = CreateS(operationGraph);

            // t(o) = 0 für alle o aus S
            foreach (var o in S)
            {
                int newStart = o.GetStartTimeBackward().GetValue();
                o.SetStartTime(newStart);
            }

            // while S not empty do
            while (S != null && S.Any())
            {
                int d_min = Int32.MaxValue;
                ProductionOrderOperation o_min = null;
                foreach (var o in S)
                {
                    // Berechne d(o) = t(o) + p(o) für alle o aus S
                    int newEnd = o.GetStartTime() + o.GetValue().Duration;
                    o.SetEndTime(newEnd);
                    // Bestimme d_min = min{ d(o) | o aus S }
                    if (o.GetEndTime() < d_min)
                    {
                        d_min = o.GetEndTime();
                        o_min = o;
                    }
                }

                // Bilde Konfliktmenge K = { o | o aus S UND M(o) == M(o_min) UND t(o) < d_min }
                IStackSet <ProductionOrderOperation> K = new StackSet <ProductionOrderOperation>();
                foreach (var o in S)
                {
                    if (o.GetValue().ResourceCapabilityId.Equals(o_min.GetValue().ResourceCapabilityId) &&
                        o.GetStartTime() < d_min)
                    {
                        K.Push(o);
                    }
                }

                // while K not empty do
                if (K.Any())
                {
                    // Entnehme Operation mit höchster Prio (o1) aus K und plane auf nächster freier Resource ein

                    List <ProductionOrderOperation> allO1 = new List <ProductionOrderOperation>();

                    foreach (var machine in resourcesByResourceCapabilityId[o_min.GetResourceCapabilityId()]
                             .OrderBy(x => x.GetIdleStartTime().GetValue()))
                    {
                        if (K.Any() == false)
                        {
                            break;
                        }

                        ProductionOrderOperation o1 = null;
                        o1 = priorityRule.GetHighestPriorityOperation(machine.GetIdleStartTime(),
                                                                      K.GetAll());
                        if (o1 == null)
                        {
                            throw new MrpRunException("This is not possible if K.Any() is true.");
                        }

                        allO1.Add(o1);

                        K.Remove(o1);

                        o1.SetMachine(machine);
                        // correct op's start time if resource's idleTime is later
                        if (machine.GetIdleStartTime().GetValue() > o1.GetStartTime())
                        {
                            int newStart = machine.GetIdleStartTime().GetValue();
                            o1.SetStartTime(newStart);
                            int newEnd = o1.GetStartTime() + o1.GetValue().Duration;
                            o1.SetEndTime(newEnd);
                        }

                        // correct op's start time if op's material is later available
                        DueTime dueTimeOfOperationMaterial = o1.GetEarliestPossibleStartTime();
                        if (dueTimeOfOperationMaterial.GetValue() > o1.GetStartTime())
                        {
                            int newStart = dueTimeOfOperationMaterial.GetValue();
                            o1.SetStartTime(newStart);
                            int newEnd = o1.GetStartTime() + o1.GetValue().Duration;
                            o1.SetEndTime(newEnd);
                        }

                        machine.SetIdleStartTime(new DueTime(o1.GetEndTime()));
                    }


                    // t(o) = d(letzte o1 aus allO1) für alle o aus K (ohne alle o1)
                    foreach (var o in K)
                    {
                        o.SetStartTime(allO1[allO1.Count - 1].GetEndTime());
                    }

                    /*if N(o1) not empty then
                     *  S = S vereinigt N(o1) ohne alle o1
                     */
                    foreach (var o1 in allO1)
                    {
                        INode o1AsNode = new Node(o1);

                        INodes allPredecessorsRecursive =
                            operationGraph.GetPredecessorNodesRecursive(o1AsNode);
                        if (allPredecessorsRecursive != null)
                        {
                            IStackSet <ProductionOrderOperation> N =
                                new StackSet <ProductionOrderOperation>(
                                    allPredecessorsRecursive.Select(x =>
                                                                    (ProductionOrderOperation)x.GetEntity()));

                            // t(o) = d(o1) für alle o aus N(o1)
                            foreach (var n in N)
                            {
                                n.SetStartTime(o1.GetEndTime());
                            }
                        }

                        // prepare for next round
                        operationGraph.RemoveNode(o1AsNode, true);
                    }

                    S = CreateS(operationGraph);
                }
            }
        }
        public static Demand CreateStockExchangeProductionOrderDemand(M_ArticleBom articleBom, DueTime dueTime)
        {
            IDbMasterDataCache dbMasterDataCache =
                ZppConfiguration.CacheManager.GetMasterDataCache();
            T_StockExchange stockExchange = new T_StockExchange();

            stockExchange.StockExchangeType = StockExchangeType.Demand;
            stockExchange.Quantity          = articleBom.Quantity;
            stockExchange.State             = State.Created;
            M_Stock stock = dbMasterDataCache.M_StockGetByArticleId(new Id(articleBom.ArticleChildId));

            stockExchange.Stock          = stock;
            stockExchange.StockId        = stock.Id;
            stockExchange.RequiredOnTime = dueTime.GetValue();
            stockExchange.ExchangeType   = ExchangeType.Withdrawal;

            StockExchangeDemand stockExchangeDemand =
                new StockExchangeDemand(stockExchange);

            return(stockExchangeDemand);
        }
コード例 #6
0
 public bool IsBeforeInterval(DueTime dueTime)
 {
     return(dueTime.GetValue() < StartAt);
 }
コード例 #7
0
ファイル: DummyNode.cs プロジェクト: smfichadiya/ng-erp-4.0
 public void SetStartTimeBackward(DueTime startTime)
 {
     throw new System.NotImplementedException();
 }
コード例 #8
0
ファイル: Demand.cs プロジェクト: smfichadiya/ng-erp-4.0
 public abstract void SetStartTimeBackward(DueTime startTime);
コード例 #9
0
 public override string ToString()
 {
     return(DueTime.ToString("dd/MM/yyyy")
            + " - "
            + Amount.ToString("F2", CultureInfo.InvariantCulture));
 }
コード例 #10
0
 public void SetIdleStartTime(DueTime nextIdleStartTime)
 {
     _idleStartTime = nextIdleStartTime.GetValue();
 }
コード例 #11
0
 internal void SetNextDueTime()
 {
     DueTime = DueTime.Add(FailureContext.CurrentPeriod);
 }
 public override void SetEndTimeBackward(DueTime endTime)
 {
     throw new NotImplementedException();
 }
 public override void SetStartTimeBackward(DueTime startTime)
 {
     // is NOT allowed to change
     throw new System.NotImplementedException();
 }
コード例 #14
0
ファイル: DummyNode.cs プロジェクト: smfichadiya/ng-erp-4.0
 public void SetEndTimeBackward(DueTime endTime)
 {
     throw new System.NotImplementedException();
 }
コード例 #15
0
        /**
         * Top-down
         */
        public void ScheduleBackward()
        {
            // S = {0} (alle einplanbaren Operations/Demands/Providers)

            if (_clearOldTimes)
            {
                // d_0 = 0
                foreach (var uniqueNode in _orderOperationGraph.GetAllUniqueNodes())
                {
                    IScheduleNode uniqueScheduleNode = uniqueNode.GetEntity();
                    if (uniqueScheduleNode.IsReadOnly() == false &&
                        uniqueScheduleNode.GetType() != typeof(CustomerOrderPart))
                    {
                        uniqueScheduleNode.ClearStartTimeBackward();
                        uniqueScheduleNode.ClearEndTimeBackward();
                    }
                }
            }

            // while S nor empty do
            while (_S.Any())
            {
                INode         i = _S.Pop();
                IScheduleNode iAsScheduleNode = i.GetEntity();

                INodes successorNodes = _orderOperationGraph.GetSuccessorNodes(i);
                if (successorNodes != null && successorNodes.Any())
                {
                    foreach (var successor in successorNodes)
                    {
                        _S.Push(successor);

                        IScheduleNode successorScheduleNode = successor.GetEntity();
                        if (successorScheduleNode.IsReadOnly())
                        {
                            continue;
                        }


                        // Konservativ vorwärtsterminieren ist korrekt,
                        // aber rückwärts muss wenn immer möglich terminiert werden
                        // (prüfe parents und ermittle minStart und setze das)
                        INodes predecessorNodes =
                            _orderOperationGraph.GetPredecessorNodes(successor);
                        DueTime minStartTime = iAsScheduleNode.GetStartTimeBackward();
                        if (minStartTime == null)
                        {
                            throw new MrpRunException(
                                      "How can the StartTime of an already scheduled node be null ?");
                        }

                        foreach (var predecessorNode in predecessorNodes)
                        {
                            DueTime predecessorsStartTime =
                                predecessorNode.GetEntity().GetStartTimeBackward();
                            if (predecessorsStartTime != null &&
                                predecessorsStartTime.IsSmallerThan(minStartTime))
                            {
                                minStartTime = predecessorsStartTime;
                            }
                        }

                        if (successorScheduleNode.GetType() == typeof(CustomerOrderPart))
                        {
                            throw new MrpRunException(
                                      "Only a root node can be a CustomerOrderPart.");
                        }

                        if (successorScheduleNode.IsReadOnly() == false)
                        {
                            successorScheduleNode.SetEndTimeBackward(minStartTime);
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: Interval.cs プロジェクト: smfichadiya/ng-erp-4.0
 public Interval(Id id, DueTime start, DueTime end)
 {
     _id    = id;
     _start = start;
     _end   = end;
 }
コード例 #17
0
 public override int GetHashCode()
 {
     return(DueTime.GetHashCode());
 }
コード例 #18
0
ファイル: Demand.cs プロジェクト: smfichadiya/ng-erp-4.0
 public abstract void SetEndTimeBackward(DueTime endTime);
        public void ScheduleForward()
        {
            Stack <INode> S = new Stack <INode>();

            // d_0 = 0
            foreach (var node in _orderOperationGraph.GetLeafNodes())
            {
                IScheduleNode scheduleNode = node.GetEntity();
                if (scheduleNode.IsReadOnly() == false &&
                    scheduleNode.GetStartTimeBackward().IsSmallerThan(_simulationInterval.GetStart()))
                {
                    // implicitly the due/endTime will also be set accordingly
                    scheduleNode.SetStartTimeBackward(_simulationInterval.GetStart());
                    S.Push(node);
                }
                else // no forward scheduling is needed
                {
                }
            }


            // while S nor empty do
            while (S.Any())
            {
                INode         i = S.Pop();
                IScheduleNode iAsScheduleNode = (IScheduleNode)i.GetEntity();

                INodes predecessors = _orderOperationGraph.GetPredecessorNodes(i);
                if (predecessors != null && predecessors.Any())
                {
                    foreach (var predecessor in predecessors)
                    {
                        IScheduleNode predecessorScheduleNode = predecessor.GetEntity();

                        // if predecessor starts before endTime of current d/p --> change that
                        if (predecessorScheduleNode.IsReadOnly() == false && predecessorScheduleNode
                            .GetStartTimeBackward().IsSmallerThan(iAsScheduleNode.GetEndTimeBackward()))
                        {
                            // COPs are not allowed to change
                            if (predecessorScheduleNode.GetType() != typeof(CustomerOrderPart))
                            {
                                // don't take getDueTime() since in case of a demand,
                                // this will be the startTime, which is to early

                                // This must be the maximum endTime of all childs !!!
                                DueTime maxEndTime = iAsScheduleNode.GetEndTimeBackward();
                                foreach (var successor in _orderOperationGraph.GetSuccessorNodes(
                                             predecessor))
                                {
                                    DueTime successorsEndTime = successor.GetEntity().GetEndTimeBackward();
                                    if (successorsEndTime.IsGreaterThan(maxEndTime))
                                    {
                                        maxEndTime = successorsEndTime;
                                    }
                                }

                                predecessorScheduleNode.SetStartTimeBackward(maxEndTime);
                            }
                        }

                        S.Push(predecessor);
                    }
                }
            }
        }
コード例 #20
0
 public override void SetProvided(DueTime atTime)
 {
     throw new System.NotImplementedException();
 }
 public abstract void SetProvided(DueTime atTime);