Concept - List, matrix problem

Noah Aas 1,110 Reputation points
2025-09-30T08:47:36.2033333+00:00

I have a process with two lanes. One input is supplied by the panel.

Sometimes lane 1 is faster, sometimes slower, this is controlled by the PLC. How can I replicate this process exactly?

Each panel must know which lane it was produced from. Do I need a std::vector? How do I recreate the lines? Matrix? Does anyone have a good concept or idea?

Panel:

  • ID
  • StartTime
  • EndTime
  • LaneNo
  • SegmentNo

Input

enter image description here

Process

enter image description here

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Varsha Dundigalla(INFOSYS LIMITED) 2,700 Reputation points Microsoft External Staff
    2025-10-01T11:53:33.8533333+00:00

    Thank you for reaching out.

    This process simulates how panels move through a two-lane manufacturing system. Each panel starts in Segment 1 of either Lane 1 or Lane 2. The PLC controls the speed of each lane, so sometimes Lane 1 is faster, sometimes Lane 2. Panels are processed in FIFO order. first, they move from Segment 1 to Segment 2, and once Segment 2 is complete, they’re marked as finished. Each panel keeps track of its lane, segment, start time, and end time throughout the process.

    Panel Representation

    Each panel carries its own metadata (ID, lane, segment, timestamps):

    struct Panel {
        int ID;
        time_t StartTime;
        time_t EndTime;
        int LaneNo; // 1 or 2
        int SegmentNo; // 1 or 2
    };
    

     Lane Processing

    Two queues represent the lanes, since panels are processed FIFO.

    A controller moves panels through segments or marks them completed.

    std::queue<Panel> lane1Queue, lane2Queue;
    std::vector<Panel> completedPanels;
     
    void processLane(std::queue<Panel>& lane, int laneNo, double speedFactor) {
        if (!lane.empty()) {
            Panel currentPanel = lane.front();
            lane.pop();
     
            currentPanel.LaneNo = laneNo;
            currentPanel.StartTime = std::time(nullptr);
     
            if (currentPanel.SegmentNo == 1) {
                // Move to next segment
                currentPanel.SegmentNo = 2;
                lane.push(currentPanel);
            } else {
                // Base processing time is ~2s, modified by lane speed
                currentPanel.EndTime = std::time(nullptr) + static_cast<int>(2.0 / speedFactor);
                completedPanels.push_back(currentPanel);
            }
        }
    }
    

    Simulating PLC-Controlled Lane Speeds

    double lane1Speed = 1.0, lane2Speed = 1.0;
     
    void simulatePLCVariableSpeed() {
        lane1Speed = 0.5 + (std::rand() % 100) / 100.0; // 0.5x to 1.5x
        lane2Speed = 0.5 + (std::rand() % 100) / 100.0;
    }
    

    Example Usage

    int main() {
        srand(static_cast<unsigned>(time(nullptr)));
     
        // Create panels and distribute across lanes
        for (int i = 0; i < 10; ++i) {
            Panel p {i, 0, 0, 0, 1}; // start in segment 1
            (i % 2 == 0 ? lane1Queue : lane2Queue).push(p);
        }
     
        // Process until all panels are done
        while (!lane1Queue.empty() || !lane2Queue.empty()) {
            processLane(lane1Queue, 1, lane1Speed);
            processLane(lane2Queue, 2, lane2Speed);
            simulatePLCVariableSpeed();
        }
     
        // Simple report
        for (auto& p : completedPanels) {
            std::cout << "Panel " << p.ID 
                      << " completed in Lane " << p.LaneNo 
                      << ", Segment " << p.SegmentNo 
                      << " (Start " << p.StartTime << ", End " << p.EndTime << ")\n";
        }
    }
    

     Key Points 

    • Each Panel retains its full trace (lane + segment + times).
    • Two queues simulate FIFO lane behavior. 
    • A simple controller decides when a panel moves to the next segment or finishes. 
    • PLC speed variation is simulated by random factors but could be replaced with real inputs. 

     Let me know if you need any further help with this. We'll be happy to assist.

    If you find this helpful, please mark this as answered.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.