Inspiration
If demand for a plant-derived medicine rises next year, what should we plant today?
The answer depends on more than the forecast. Plants take time to grow, land is limited, and medicine quantities must first be translated into plant material. That is the planning challenge behind AgriPharm.
Many everyday medicines still start in a field. Colchicine comes from Gloriosa superba seed, digoxin from Digitalis lanata leaf, pilocarpine from jaborandi (Pilocarpus microphyllus) and atropine from Atropa belladonna. Growers usually plant without knowing how much of these medicines patients will actually need. Some species are still collected from the wild: jaborandi has been listed as endangered in Brazil since 2008, and cultivating it is one way to take pressure off wild populations.
Our connection to this problem is personal. We are students from agricultural regions, including Crete and Agrinio. We want to explore how our technical skills could help local producers evaluate new cultivation opportunities before committing land, time, and money.
We wanted to connect the two ends of that chain. For this prototype, we started with French medicine reimbursement data and built a workflow connecting demand forecasts with agricultural planning. We translate real pharmacy demand into kilograms of a named plant, and tell a grower what to sow, when, and on how much land. That way, demand is met without clearing more land than needed.
What it does
AgriPharm is a decision-support tool that goes from medicine sales to a planting calendar:
- Forecasts demand. It predicts the next 12 months (Aug 2026 – Jul 2027) of reimbursed medicine boxes for 8 plant-derived drugs. The forecasts use French Medic'AM data (Assurance Maladie).
- Converts boxes into plant material. Each box becomes milligrams of active ingredient, then kilograms of a specific plant part (seed, dry leaf). For example, about 1.46 million colchicine boxes a year correspond to roughly 6.2 t of Gloriosa seed at ideal recovery.
- Optimizes the planting plan. A monthly linear program decides how many stremmata (1 stremma = 1,000 m²) of each plant to sow in each month, within sowing windows and growth cycles. It maximizes the demand covered with the land available.
- Simulates the field. A weekly simulation plays the plan out with temperature-driven growth, so seasons can stretch a crop's cycle.
- Stress-tests the plan. It runs a drought scenario and a two-stage stochastic model over six demand and yield scenarios.
The live dashboard lets you move the available land and watch the field, the yearly coverage and the comparisons update.
How we built it
- Forecasting: We used 175 months of Medic'AM data (Jan 2012 – Jul 2026) and fit one SARIMA model per ATC5 code with
pmdarima(12-month seasonality). We tested each model on a 12-month hold-out. Two series needed manual cleaning: we trimmed artemether's pre-market months and removed an anomalous spike in the etoposide series. Hold-out MAPE ranges from 2.9% (pilocarpine) to 25.6% (scopolamine). - Drug-to-plant conversion: We mapped 34 commercial presentations to their ingredient content. Their January–June 2026 box volumes give a volume-weighted mg-per-box figure. We corrected for salts and precursors and applied plant concentrations from published studies. A validator reconciles the source sheets, reproduces every output and runs 14 converter tests.
- Optimization:
crop_optis a monthly LP in PuLP, solved with CBC. It plans 48 months and reports the first 36. The extra year is a buffer against end-of-horizon effects. Constraints cover land in use (including crops still growing), sowing windows, growth cycles and monthly stock balance. Unmet demand is treated as lost, not deferred. - Platform: A Flask API on Render runs the optimizer, the simulation, the baselines and the stochastic analysis. A React + Vite + TypeScript dashboard on Netlify turns the results into interactive charts.
Challenges we ran into
- No database links a drug to a crop. One ATC code covers several pack sizes and strengths. Some drugs are salts. Others are made from a plant precursor through semisynthesis. Two of our eight drugs, vinorelbine and etoposide, have no defensible plant-to-ingredient yield in the literature. We report them as open gaps rather than invent a number.
- Noisy demand series. Market entry, outliers and sudden shocks made some series hard to forecast. That is why the forecasting step keeps a human reviewing each model.
- An LP doesn't feel the weather. Fixed growth cycles look optimal on paper. In a temperate climate, though, Pilocarpus cannot finish its cycle every year. We built a weekly simulation to show that gap.
- Keeping four modules consistent. Units, month conventions and hand-off files had to line up between forecasting, conversion, optimization and the web app.
Accomplishments that we're proud of
- A working chain from open public data to a month-by-month planting plan, live on the web.
- A traceable conversion: every kilogram can be followed back to a pack, a concentration and a source, and the numbers are reproducible.
- Clear results at 400 stremmata (40 ha):
- The LP covers 94% of steady-state demand; the weekly simulation, 89%.
- Coverage levels off at about 95% from roughly 500 stremmata, which shows how much land is enough.
- The optimized plan matches a greedy baseline on coverage but leaves 16% of the harvest unused versus 26%.
- If yields fall 25% after the plan is committed, coverage drops to 66%. Planning for the drought in advance brings it back to 80%.
- Across six demand and yield scenarios, the stochastic plan raises expected coverage from 79.4% to 82.7%. Perfect information would give 85.9%.
What we learned
- Most of the uncertainty is in the bridge from drug to plant, not in the forecast. "How many drugs actually have a usable plant route" is a result in itself: 6 of our 8 do.
- With land as the only constraint, the LP behaves like a greedy allocation. Optimization earns its keep through timing, reduced waste, and planning under drought and uncertainty.
- Clear data contracts between team members matter as much as the models.
What's next for AgriPharm
- Local pilots: add soil, water and climate data for a real region, with input from agronomists and pharmacists.
- Better conversion factors: use measured extraction and semisynthesis yields, and close the vinorelbine and etoposide gaps.
- Perennial crops: model multiple harvests from one planting, plus establishment years.
- More resources: add cost, water and labour constraints alongside land.
- Automatic updates: refresh forecasts as new Medic'AM releases come out.
Built With
- cbc
- flask
- framer-motion
- github
- gunicorn
- jupyter
- matplotlib
- netlify
- npm
- numpy
- openpyxl
- pandas
- pmdarima
- pulp
- python
- react
- recharts
- render
- scikit-learn
- tailwindcss
- tremor
- typescript
- uv
- vite