← Semua tutorial · Twinworks

Tutorial 7 dari 12

Otomatisasi dengan API / MCP

Mahir 15 mnt

Jalankan engine Twinworks dari skrip dan agen AI — simulasikan model, urutkan bottleneck, sapu dan optimalkan buffer, seimbangkan lini, serta periksa rumus antrean dengan permintaan dan respons JSON sungguhan.

Engine simulasi di ruang kerja adalah kode TypeScript yang sama yang menjalankan enam alat di API dan server MCP usefulweb; alat ketujuh, Penjadwal Transportasi Material, dibahas di Kendaraan bersama, jadwal transportasi, dan pemeriksaan model. Hasilnya deterministik: model dan seed yang sama selalu menghasilkan angka yang sama, baik di aplikasi maupun di server.

ID alat (REST)Nama MCPFungsinya
twinworks-simulatetwinworks_simulateModel + durasi run + seed + replikasi → KPI dengan interval kepercayaan, statistik per stasiun, bottleneck, biaya
twinworks-bottleneck-analysistwinworks_bottleneck_analysisBottleneck terperingkat (metode periode aktif) + perolehan what-if + rekomendasi
twinworks-buffer-sweeptwinworks_buffer_sweepMenyapu ukuran buffer (atau parameter lain) → kurva throughput dan titik lutut
twinworks-buffer-allocationtwinworks_buffer_allocationMembagikan sejumlah tempat buffer yang tetap untuk throughput maksimum (greedy, bilangan acak bersama)
twinworks-line-balancetwinworks_line_balanceTugas + urutan pendahulu + takt → penugasan stasiun, efisiensi, indeks kehalusan
twinworks-queue-formulastwinworks_queue_formulasM/M/1, M/M/c, M/D/1, M/G/1, Kingman — opsional diverifikasi dengan simulasi

Di ruang kerja, Bantuan → Otomatisasi dengan API / MCP menampilkan permintaan siap salin untuk model kamu saat ini.

Dialog API dengan permintaan untuk model saat ini

1. Simulasikan templat

Setiap alat model menerima ID template atau model — JSON dari Berkas → Ekspor → JSON model (skenario aktif), yang dikirim sebagai string.

curl -s -X POST https://twinworks.usefulweb.site/api/v1/tools/twinworks-simulate/calculate \
  -H 'content-type: application/json' \
  -d '{"template":"three-station-line","horizonHours":8,"replications":5,"seed":42}'

Respons (dipersingkat):

{
  "summary": "3-station line: 64.1 ± 3.4 good parts/h (95 % CI, 5 replications), mean lead time 304 s, WIP 5.53; bottleneck: Mill.",
  "result": {
    "replications": 5,
    "seeds": [42, 3029642774, 2605890936, 2032093786, 1137000544],
    "throughputPerHour": { "mean": 64.1333, "lo": 60.7384, "hi": 67.5282, "halfWidth": 3.3949, "n": 5 },
    "little": { "L": 6.8785, "lambdaPerHour": 66.6667, "W": 369.285, "lambdaW": 6.8386, "relError": 0.00581, "ok": true },
    "stations": [
      { "id": "M2", "name": "Mill", "utilization": 0.9126,
        "states": { "busy": 0.9126, "setup": 0, "waitop": 0, "blocked": 0, "idle": 0.0874, "down": 0, "maint": 0, "off": 0 },
        "availability": 1, "performance": 0.903, "quality": 1, "oee": 0.903 }
    ],
    "bottleneck": { "primary": "M2", "ranking": [ { "id": "M2", "name": "Mill", "sole": 0.8252, "shifting": 0.0606, "total": 0.8858 } ] },
    "openInAppUrl": "https://twinworks.usefulweb.site/app#project=…"
  }
}

seeds mencantumkan seed dari setiap replikasi, sehingga setiap run bisa direproduksi dengan tepat. little membandingkan WIP yang terukur dengan throughput × lead time dari replikasi pertama (hukum Little) — pemeriksaan cepat untuk memastikan model masuk akal. openInAppUrl membuka model di ruang kerja.

2. Model milikmu sendiri, diperiksa secara manual

Sebuah lini dua mesin yang deterministik: pasokan tak terbatas, M1 = 30 s, buffer dengan 3 tempat, M2 = 40 s. Simpan sebagai two-machines.json:

{
  "name": "Two machines",
  "settings": { "horizon": 7200, "warmup": 600 },
  "nodes": [
    { "id": "S", "type": "source", "arrival": "saturated" },
    { "id": "M1", "type": "machine", "cycle": { "type": "constant", "value": 30 } },
    { "id": "B", "type": "buffer", "capacity": 3 },
    { "id": "M2", "type": "machine", "cycle": { "type": "constant", "value": 40 } },
    { "id": "OUT", "type": "sink" }
  ],
  "links": [ { "from": "S", "to": "M1" }, { "from": "M1", "to": "B" }, { "from": "B", "to": "M2" }, { "from": "M2", "to": "OUT" } ]
}

Kolom model berisi teks (JSON sebagai string), jadi berkas tersebut disematkan dengan jq:

jq -n --rawfile m two-machines.json '{model: $m, replications: 1}' |
  curl -s -X POST https://twinworks.usefulweb.site/api/v1/tools/twinworks-simulate/calculate \
       -H 'content-type: application/json' --data @-

Hasil: "summary": "Two machines: 90 good parts/h (single run), mean lead time 240 s, WIP 6; bottleneck: Machine M2." (Dua mesin: 90 komponen baik/jam (satu run), rata-rata lead time 240 s, WIP 6; bottleneck: mesin M2.)

Itu persis sesuai teori untuk lini deterministik: throughput = 1 / waktu siklus bottleneck = 3600 / 40 = 90 komponen/jam. M1 sibuk 30/40 = 75 % dan terblokir pada 25 % sisanya, M2 sibuk 100 %. Hukum Little berlaku dengan tepat: L = λ·W = (90 / 3600 s) × 240 s = 6 komponen di dalam sistem.

Jenis distribusi: constant {value}, uniform {min,max}, triangular {min,mode,max}, normal {mean,sd} (dipotong di 0), exponential {mean}, lognormal {mean,sd}. Format lengkapnya ada di /project.schema.json.

3. Urutkan bottleneck dan uji perbaikan

curl -s -X POST https://twinworks.usefulweb.site/api/v1/tools/twinworks-bottleneck-analysis/calculate \
  -H 'content-type: application/json' \
  -d '{"template":"bottleneck-buffer-sizing","replications":3}'
{
  "summary": "\"OP30 Hone\" is the main bottleneck (58.3% of the time; best tested fix: Add a parallel server at \"OP30 Hone\" (1 → 2), +7.85 parts/h).",
  "result": {
    "primary": "M3",
    "ranking": [
      { "rank": 1, "id": "M3", "name": "OP30 Hone", "sole": 0.4043, "shifting": 0.1788, "total": 0.5831, "utilization": 0.8477 },
      { "rank": 2, "id": "M2", "name": "OP20 Bore", "sole": 0.2613, "shifting": 0.1628, "total": 0.4241, "utilization": 0.7929 }
    ],
    "recommendations": [ "\"OP30 Hone\" is the bottleneck 58.3% of the time (40.4% sole, 17.9% shifting): …" ]
  }
}

4. Sapu buffer

{ "template": "bottleneck-buffer-sizing", "target": "B2", "parameter": "capacity", "from": 1, "to": 8, "step": 1, "replications": 4 }

Kirim dengan POST ke /api/v1/tools/twinworks-buffer-sweep/calculate:

{
  "summary": "Throughput ranges from 99.6 to 105.8 parts/h over buffer capacity 1…8 at B2; knee point at 3.",
  "result": {
    "points": [
      { "value": 1, "throughput": { "mean": 99.5682, "lo": 95.1451, "hi": 103.9913 }, "wip": { "mean": 7.9107 }, "bottleneck": "M3" },
      { "value": 2, "throughput": { "mean": 102.4318, "lo": 97.7379, "hi": 107.1257 }, "wip": { "mean": 8.6199 }, "bottleneck": "M3" },
      { "value": 3, "throughput": { "mean": 103.7273, "lo": 99.2019, "hi": 108.2527 }, "wip": { "mean": 9.285 }, "bottleneck": "M3" }
    ]
  }
}

Semua titik sapuan memakai seed replikasi yang sama, sehingga kurvanya mulus dan perbedaan antartitik benar-benar bermakna.

5. Optimalkan alokasi buffer

{ "template": "bottleneck-buffer-sizing", "total": 8, "replications": 3, "horizonHours": 6 }

Kirim dengan POST ke /api/v1/tools/twinworks-buffer-allocation/calculate:

{
  "summary": "8 buffer places: B1=1, B2=4, B3=2, B4=1 gives 97.13 parts/h (current allocation 95.2, significant gain); 6 well-placed places already reach the current throughput.",
  "result": {
    "best": { "capacities": { "B1": 1, "B2": 4, "B3": 2, "B4": 1 } },
    "gain": { "mean": 1.9333, "lo": 1.6465, "hi": 2.2202 },
    "placesForCurrentThroughput": 6,
    "evaluations": 18
  }
}

result.model adalah model dengan kapasitas yang sudah dioptimalkan, siap dipakai untuk twinworks-simulate. Hilangkan total untuk membagikan ulang jumlah tempat yang ada saat ini; buffers (misalnya "B2,B3") membatasi optimasi hanya pada buffer tertentu.

Optimasi alokasi buffer yang sama di dialog ruang kerja, dengan jumlah tempat saat ini dan hasil optimasi per buffer

6. Seimbangkan lini

{
  "tasks": [
    { "id": "A", "time": 60, "predecessors": "" },   { "id": "B", "time": 40, "predecessors": "A" },
    { "id": "C", "time": 55, "predecessors": "B" },  { "id": "D", "time": 50, "predecessors": "A" },
    { "id": "E", "time": 30, "predecessors": "D" },  { "id": "F", "time": 45, "predecessors": "D" },
    { "id": "G", "time": 20, "predecessors": "F" },  { "id": "H", "time": 35, "predecessors": "C,E,G" }
  ],
  "availableMinutes": 450, "demand": 270, "method": "best"
}

→ "4 stations for a takt time of 100 s (theoretical minimum 4), efficiency 83.8%, smoothness index 47.7 s." (4 stasiun untuk waktu takt 100 s (minimum teoretis 4), efisiensi 83,8%, indeks kehalusan 47,7 s.) dengan stasiun [A,B], [D,F], [C,E], [G,H]. Hasilnya juga memuat model siap simulasi dari lini yang sudah diseimbangkan.

7. Periksa rumus antrean

{ "queue": "mm1", "arrivalsPerHour": 60, "serviceTime": 48, "verify": true, "replications": 10 }

→ "M/M/1: utilization 80%, mean wait 192 s, mean queue 3.2; simulation confirms the result." (M/M/1: utilisasi 80%, rata-rata waktu tunggu 192 s, rata-rata antrean 3,2; simulasi mengonfirmasi hasilnya.) Blok verification berisi rata-rata waktu tunggu hasil simulasi 193.4 s dengan interval 95 % [177.2, 209.6], yang mencakup nilai eksak 192 s.

8. Gunakan dari agen AI (MCP)

Tambahkan endpoint MCP https://twinworks.usefulweb.site/mcp ke klien MCP-mu (Claude Desktop, Cursor, …). Nama alat memakai garis bawah:

{
  "jsonrpc": "2.0", "id": 2, "method": "tools/call",
  "params": {
    "name": "twinworks_bottleneck_analysis",
    "arguments": { "template": "bottleneck-buffer-sizing", "replications": 3 }
  }
}

Responsnya berisi ringkasan sebagai teks plus JSON lengkap di structuredContent. Contoh prompt yang bagus: "Ini lini saya dalam format JSON Twinworks. Temukan bottleneck-nya, lalu sapu buffer di depannya dari 1 sampai 8 dan beri tahu saya ukuran terkecil yang memberikan 95 % dari perolehannya."

Batasan

Satu replikasi boleh membutuhkan paling banyak 6 juta event. API menerima hingga 30 replikasi untuk twinworks-simulate dan hingga 20 per titik untuk alat analisis dan sapuan, dengan durasi run hingga 2.400 jam. Untuk studi yang lebih besar, gunakan ruang kerja (berjalan di Web Worker) atau bagi pekerjaannya ke beberapa panggilan.

Siap mencobanya?

Buka Twinworks →