An interactive lesson · Operations Research درس تفاعلي · بحوث العمليات

Field Workforce
Scheduling, solved.
جدولة القوى العاملة
الميدانية، محلولة.

How modern AI assigns thousands of technicians to thousands of jobs — without breaking a single constraint, in seconds rather than centuries. كيف يوزّع الذكاء الاصطناعي الحديث آلاف الفنيين على آلاف المهام — دون كسر أي قيد، في ثوانٍ بدلاً من قرون.

Duration المدة
~ 45 minutes ٤٥ دقيقة
Level المستوى
CS / IE undergrad جامعي · حاسوب وصناعية
Sections الأقسام
8 sections ٨ أقسام
Scroll ↓ اسحب ↓
01
Chapter one الفصل الأول

The problem, in plain words. المشكلة، ببساطة.

A maintenance company has 30 technicians and 200 customer jobs spread across a city. Each technician has different skills, working hours, and a starting location. Each job requires a specific skill, fits within a time window, and takes a different amount of time to complete.

تخيّل شركة صيانة لديها ٣٠ فنياً و٢٠٠ مهمة موزّعة على المدينة. كل فني له مهارات مختلفة، وساعات عمل، وموقع انطلاق. وكل مهمة تتطلب مهارة محددة، وتقع ضمن نافذة زمنية، وتستغرق وقتاً مختلفاً.

"Who goes where? When? In what order?" «مَن يذهب إلى أين؟ متى؟ وبأي ترتيب؟»

This is the heart of Field Workforce Scheduling (FWS): a generalization of the classic Vehicle Routing Problem with Time Windows (VRPTW), augmented with skills, priorities, and resource constraints. It belongs to the class of NP-hard combinatorial optimization problems — meaning no known algorithm can solve every instance optimally in polynomial time.

هذي هي جوهر مشكلة Field Workforce Scheduling (FWS): تعميم لمشكلة توجيه المركبات بنوافذ زمنية (VRPTW) الكلاسيكية، مع إضافة المهارات والأولويات وقيود الموارد. وتنتمي إلى فئة مسائل التحسين التوافقية NP-hard — أي لا توجد خوارزمية معروفة تحل كل الحالات بشكل مثالي في زمن متعدد الحدود.

i.
Inputs المدخلات
What we're given ما هو متاح
A set of technicians (with skills, hours, locations) and a set of jobs (with required skills, durations, time windows, locations). مجموعة من الفنيين (بمهاراتهم وساعاتهم ومواقعهم) ومجموعة من المهام (بمهاراتها المطلوبة ومدّتها ونوافذها الزمنية ومواقعها).
ii.
Decisions القرارات
What we choose ما نختاره
For each job: which technician handles it, at what time, and in what sequence within their daily route. لكل مهمة: أي فني سيُنفّذها، وفي أي وقت، وبأي ترتيب ضمن مسار يومه.
iii.
Objective الهدف
What we optimize ما نسعى لتحسينه
Minimize total cost (travel time, overtime, unassigned jobs) — or maximize jobs completed and customer satisfaction. تقليل التكلفة الإجمالية (وقت التنقل، الساعات الإضافية، المهام غير المُسندة) — أو زيادة المهام المُنجزة ورضا العملاء.
02
Chapter two الفصل الثاني

Translating reality into math. من الواقع إلى الرياضيات.

Before any algorithm can solve our problem, we must translate it into mathematical language. This is the most important skill in operations research: turning a messy real-world situation into a precise formulation.

قبل أن تحلّ أي خوارزمية مشكلتنا، يجب علينا ترجمتها إلى لغة رياضية. هذي أهم مهارة في بحوث العمليات: تحويل موقف واقعي معقد إلى صياغة دقيقة.

Sets · المجموعات T = { 1, 2, ..., n }  // set of technicians J = { 1, 2, ..., m }  // set of jobs S = { 1, 2, ..., k }  // set of skills
Decision variables · متغيرات القرار xij {0, 1}  // 1 if technician i is assigned to job j sj 0  // start time of job j yijk {0, 1}  // 1 if technician i goes from job j to job k
Objective function · دالة الهدف minimize   Σi ∈ T Σj,k ∈ J  cjk · yijk  +  Σj ∈ J pj · (1 Σi xij) // minimize: travel cost + penalty for unassigned jobs
Subject to · بالقيود (1)   Σi ∈ T xij 1  ∀ j J  // each job assigned at most once (2)   xij aij  ∀ i, j  // technician must have required skill (3)   ej sj lj  ∀ j  // time window constraint (4)   sk sj + dj + tjk  if yijk = 1  // travel time between jobs (5)   Σj dj · xij Hi  ∀ i  // max working hours per technician

Now we have a Mixed Integer Linear Program (MILP). Solvers like Gurobi, CPLEX, or open-source OR-Tools CP-SAT can take this formulation and search for an optimal — or near-optimal — solution.

الآن لدينا برنامج خطي عدد صحيح مختلط (MILP). الحلّالات مثل Gurobi، أو CPLEX، أو OR-Tools CP-SAT مفتوح المصدر يمكنها أن تأخذ هذه الصياغة وتبحث عن حلّ أمثل — أو شبه أمثل.

03
Chapter three الفصل الثالث

Hard versus soft constraints. قيود صارمة وقيود ليّنة.

Constraints come in two flavors. Hard constraints must never be violated — a plumber cannot fix a wiring fault. Soft constraints are preferences we'd like to honor but can sacrifice if they conflict — preferring morning appointments, or balancing workload across technicians.

القيود نوعان. القيود الصارمة (Hard) لا يجوز كسرها أبداً — السبّاك لا يمكنه إصلاح عطل كهربائي. القيود اللينة (Soft) هي تفضيلات نحب الالتزام بها، لكن يمكن التضحية بها عند التعارض — كتفضيل المواعيد الصباحية، أو موازنة الحمل بين الفنيين.

i
Skill matching مطابقة المهارات
Technician must possess the skill required by the job. يجب أن يمتلك الفني المهارة المطلوبة للمهمة.
Hard صارم
ii
Time windows النوافذ الزمنية
Job must start within its allowed window [earliest, latest]. يجب بدء المهمة ضمن نافذتها الزمنية المسموحة.
Hard صارم
iii
Working hours ساعات العمل
Total daily work for each technician must not exceed their max hours. إجمالي ساعات العمل اليومية لكل فني لا يتجاوز الحد الأقصى.
Hard صارم
iv
Travel feasibility جدوى التنقل
Two consecutive jobs must allow enough time to travel between them. يجب أن يسمح الوقت بين مهمتين متتاليتين بالتنقل بينهما.
Hard صارم
v
Workload balance موازنة الحمل
Distribute jobs roughly evenly to prevent burnout and bottlenecks. توزيع المهام بشكل متوازن لتجنّب الإرهاق والاختناقات.
Soft ليّن
vi
Customer preference تفضيل العميل
Honor preferred technicians or appointment times when possible. احترام تفضيلات العميل في الفني أو الوقت كلما أمكن.
Soft ليّن
vii
Priority weighting ترجيح الأولوية
Higher-priority jobs (emergencies, SLA breaches) get scheduled first. المهام عالية الأولوية (الطوارئ، انتهاكات اتفاقيات الخدمة) تُجدول أولاً.
Soft ليّن
04
Chapter four الفصل الرابع

Four ways AI tackles the problem. أربع طرق يعالج بها الذكاء الاصطناعي المشكلة.

No single algorithm dominates. Real-world systems combine several techniques — exact methods for clean sub-problems, metaheuristics for the messy whole, and machine learning for forecasting and adaptation.

لا توجد خوارزمية واحدة تتفوّق على الجميع. الأنظمة الحقيقية تدمج عدة تقنيات — طرق دقيقة للمشاكل الفرعية الصغيرة، وخوارزميات استدلالية للمشكلة الكاملة، وتعلّم آلي للتنبؤ والتكيّف.

i

Constraint Programming البرمجة بالقيود

CP-SAT · MILP · Branch & bound CP-SAT · MILP · فروع وحدود
Encodes constraints directly into a solver. Finds provably optimal solutions when they exist. Best for medium problems (up to ~500 jobs). يُدخل القيود مباشرة في الحلّال. يجد حلولاً مثالية مُثبتة عند وجودها. الأنسب للمشاكل المتوسطة (حتى ٥٠٠ مهمة تقريباً).
Speedالسرعة ★★★☆☆
Qualityالجودة ★★★★★
ii

Metaheuristics الخوارزميات الاستدلالية

Genetic · Tabu · Simulated annealing جينية · تابو · تلدين محاكى
Smart trial-and-error guided by intuition from biology and physics. Scales to thousands of jobs but offers no optimality guarantee. تجربة وخطأ ذكية مستوحاة من البيولوجيا والفيزياء. تتوسّع لآلاف المهام لكن دون ضمان مثالية الحل.
Speedالسرعة ★★★★★
Qualityالجودة ★★★★☆
iii

Machine Learning تعلّم الآلة

XGBoost · Neural networks · Time-series XGBoost · شبكات عصبية · سلاسل زمنية
Learns from history to predict job duration, no-shows, and traffic. Doesn't schedule directly — feeds richer estimates into the optimizer. يتعلّم من التاريخ ليتنبّأ بمدة المهام والغياب والازدحام. لا يُجدول مباشرة — لكنه يُغذّي المُحسّن بتقديرات أدق.
Roleالدور Predictive تنبؤي
Pairs withيقترن مع CP / GA
iv

Reinforcement Learning التعلّم المعزّز

Deep Q-Networks · PPO · Actor-Critic شبكات Q عميقة · PPO · ممثل-ناقد
An agent learns dispatching policy from millions of simulated days. Excels at dynamic scheduling — emergencies arriving mid-day, cancellations, traffic. عميل يتعلّم سياسة التوزيع من ملايين الأيام المُحاكاة. يتفوّق في الجدولة الديناميكية — الطوارئ المفاجئة، الإلغاءات، الازدحام.
Best forالأنسب لـ Dynamic ديناميكي
Costالكُلفة Training-heavy تدريب مكثّف
05
Chapter five الفصل الخامس

Try it yourself. جرّبها بنفسك.

Three interactive simulators to build intuition. Move the sliders, watch the schedules form, and see how AI decisions ripple across the system.

ثلاثة محاكيات تفاعلية لبناء الحدس. حرّك المنزلقات، وشاهد الجداول تتكوّن، ولاحظ كيف تنتشر قرارات الذكاء الاصطناعي عبر النظام.

Combinatorial complexity التعقيد التوافقي
Possibilities الاحتمالات
Brute force قوة غاشمة
AI solver حلّال AI
Speedup التسريع
Total distance المسافة الإجمالية
Solve time زمن الحل
Iterations التكرارات
Algorithm الخوارزمية
Nearest + 2-opt
Jobs assigned المهام المُسنَدة
Jobs unfeasible مهام غير قابلة
Solution quality جودة الحل
Imbalance عدم التوازن
06
Chapter six الفصل السادس

From theory to working code. من النظرية إلى كود يعمل.

Below is a minimal but complete example using Google OR-Tools in Python. This code solves a small Field Workforce Scheduling instance with skills, time windows, and travel times.

أدناه مثال صغير لكنه كامل باستخدام Google OR-Tools بلغة Python. هذا الكود يحلّ حالة صغيرة من جدولة القوى العاملة الميدانية مع المهارات والنوافذ الزمنية وأزمنة التنقل.

Python · OR-Tools CP-SAT
from ortools.sat.python import cp_model

# --- Problem data ---
technicians = ["T1", "T2", "T3"]
jobs = [
    # (id, skill, duration_min, earliest, latest)
    ("J1", "plumb", 60,  540, 720),   # 9:00–12:00
    ("J2", "elec",  90,  600, 780),
    ("J3", "plumb", 45,  660, 900),
    ("J4", "hvac",  120, 540, 840),
]
skills = {"T1": ["plumb"], "T2": ["elec", "hvac"], "T3": ["plumb", "hvac"]}

# --- Build the model ---
model = cp_model.CpModel()

# Decision variables
x = {}  # x[j, t] = 1 if job j assigned to tech t
start = {}  # start time of job j

for j_id, skill, dur, e, l in jobs:
    start[j_id] = model.NewIntVar(e, l, f"start_{j_id}")
    for t in technicians:
        x[j_id, t] = model.NewBoolVar(f"x_{j_id}_{t}")
        # Skill matching constraint
        if skill not in skills[t]:
            model.Add(x[j_id, t] == 0)

# Each job assigned to exactly one technician
for j_id, _, _, _, _ in jobs:
    model.Add(sum(x[j_id, t] for t in technicians) == 1)

# --- Solve ---
solver = cp_model.CpSolver()
solver.parameters.max_time_in_seconds = 10.0
status = solver.Solve(model)

if status == cp_model.OPTIMAL:
    for j_id, _, _, _, _ in jobs:
        for t in technicians:
            if solver.Value(x[j_id, t]):
                print(f"{j_id} → {t} at minute {solver.Value(start[j_id])}")

And here's a genetic algorithm approach in pure Python — no external libraries — to give you a feel for how metaheuristics search the solution space.

وأدناه نهج الخوارزمية الجينية بلغة Python نقية — بدون مكتبات خارجية — لتذوّق كيف تبحث الخوارزميات الاستدلالية في فضاء الحلول.

Python · Genetic Algorithm
import random

def fitness(chromosome, jobs, distances):
    # Lower is better: total travel + penalty for unassigned jobs
    total = 0
    for tech_route in chromosome:
        for i in range(len(tech_route) - 1):
            total += distances[tech_route[i]][tech_route[i+1]]
    return total

def crossover(parent1, parent2):
    # One-point crossover between two solutions
    cut = random.randint(1, len(parent1) - 1)
    return parent1[:cut] + parent2[cut:]

def mutate(chromosome, rate=0.1):
    # Swap two random jobs between technicians
    if random.random() < rate:
        a, b = random.sample(range(len(chromosome)), 2)
        chromosome[a], chromosome[b] = chromosome[b], chromosome[a]
    return chromosome

def genetic_algorithm(jobs, distances, generations=500, pop_size=100):
    # Initial random population
    population = [random_solution(jobs) for _ in range(pop_size)]
    
    for gen in range(generations):
        # Evaluate fitness
        scored = [(fitness(c, jobs, distances), c) for c in population]
        scored.sort()
        
        # Select top 50% as parents
        parents = [c for _, c in scored[:pop_size // 2]]
        
        # Create next generation via crossover and mutation
        next_gen = parents[:]
        while len(next_gen) < pop_size:
            p1, p2 = random.sample(parents, 2)
            child = mutate(crossover(p1, p2))
            next_gen.append(child)
        
        population = next_gen
    
    return min(population, key=lambda c: fitness(c, jobs, distances))
07
Chapter seven الفصل السابع

In the wild. في الواقع.

These aren't textbook problems — they're systems running today, dispatching workers and saving billions in fuel and labor.

هذي ليست مشاكل في كتاب مدرسي — بل أنظمة تعمل اليوم، توزّع العمالة وتوفّر مليارات في الوقود والأجور.

UPS · ORION
Last-mile delivery التوصيل النهائي
UPS's On-Road Integrated Optimization and Navigation system reroutes 55,000 drivers daily using a custom branch-and-bound solver. نظام التوجيه والتحسين المتكامل في UPS يُعيد توجيه ٥٥٠٠٠ سائق يومياً باستخدام حلّال branch-and-bound مُخصّص.
Annual saving التوفير السنوي 100M mi
Uber · Marketplace
Real-time matching المطابقة الفورية
Uber's marketplace solves a continuous online assignment problem — matching riders to drivers in milliseconds while respecting surge zones and ETAs. سوق Uber يحلّ مشكلة إسناد مستمرة — مطابقة الركاب بالسائقين في أجزاء من الثانية مع مراعاة مناطق الزيادة وأوقات الوصول.
Decisions / sec قرار / ثانية 15,000+
Aramco
Field maintenance صيانة الحقول
Saudi Aramco schedules maintenance crews across thousands of wells and pipelines using hybrid CP-SAT and machine learning forecasts. أرامكو السعودية تُجدول فرق الصيانة عبر آلاف الآبار وخطوط الأنابيب باستخدام CP-SAT الهجين وتنبؤات تعلّم الآلة.
Sites managed المواقع المُدارة 10K+
STC
Telecom installs تركيبات الاتصالات
Saudi Telecom dispatches fiber installation and repair crews across the Kingdom, balancing skill mix with citizen-facing SLAs. الاتصالات السعودية توزّع فرق تركيب وإصلاح الألياف عبر المملكة، موازنةً بين تنوّع المهارات واتفاقيات الخدمة مع المواطنين.
Daily jobs المهام اليومية 8K+
08
Chapter eight الفصل الثامن

Test your understanding. اختبر فهمك.

Six questions, ranging from concept to application. Pick an answer to see whether it's correct — and why.

ست أسئلة، من المفاهيم إلى التطبيق. اختر إجابة لترى إن كانت صحيحة — ولماذا.

0
out of 6 correct من ٦ إجابات صحيحة