SlideShare a Scribd company logo
1 of 16
Download to read offline
Melvin Zhang
melvin@melvinzhang.net
@melvinzhangzy
theintelligentwarehouse.com
magarena.github.io
Optimization: shortest path
https://www.google.com.sg/maps
Optimization: best fit line
https://en.wikipedia.org/wiki/Least squares
Optimization: model with least error
https://medium.com/onfido-tech/machine-learning-101-be2e0a86c96a
Most optimizations problems are hard
https://xkcd.com/287/
Constraint Programming
http://www.minizinc.org/
Solver independent modelling language
Jake is 3 years older than Kyla and 2 years
younger than Larry. The total of their ages is
41 years. Find Jake’s age.
Demo: a word problem
https://www.singaporemath.com/v/sf tmbm.pdf
var int: jake_age;
var int: kyla_age;
var int: larry_age;
int: sum = 41;
constraint jake_age = kyla_age + 3;
constraint jake_age + 2 = larry_age;
constraint jake_age + kyla_age + larry_age = sum;
solve satisfy;
output [
"jake : ", show(jake_age), "n",
"kyla : ", show(kyla_age), "n",
"larry: ", show(larry_age)
];
Under the hood
https://wiki.onap.org/display/DW/
Demo: https://xkcd.com/287/
int: n = 6;
array[1..n] of int: price =
[215, 275, 335, 355, 420, 580];
int: total = 1505;
array[1..n] of var int: cnt;
var int: z = sum(i in 1..n) (cnt[i]);
solve minimize z;
constraint total = sum(i in 1..n) (cnt[i]*price[i])
constraint forall(i in 1..n) (cnt[i] >= 0)
output [
show(cnt)
];
Demo: a FOSSASIA special
F O S S
+ A S I A
---------
2 0 1 8
include "alldifferent.mzn";
enum letters = {F, O, S, A, I};
int: sum = 2018;
array[letters] of var 0..9: v;
constraint 1000 * v[F] + 100 * v[O] + 10 * v[S] + v[S]
+ 1000 * v[A] + 100 * v[S] + 10 * v[I] + v[A]
= sum;
constraint alldifferent(v);
solve satisfy;
output [
show(v)
];
Conclusion
References
A MiniZinc tutorial:
https://www.minizinc.org/downloads/doc-latest/minizinc-tute.pdf
Various MiniZinc models:
http://www.hakank.org/minizinc/

More Related Content

More from Melvin Zhang

Functional programming from first principles
Functional programming from first principlesFunctional programming from first principles
Functional programming from first principlesMelvin Zhang
 
Binary Lambda Calculus and Combinatory Logic
Binary Lambda Calculus and Combinatory LogicBinary Lambda Calculus and Combinatory Logic
Binary Lambda Calculus and Combinatory LogicMelvin Zhang
 
AMKSS Career Conference 2015: Programming
AMKSS Career Conference 2015: ProgrammingAMKSS Career Conference 2015: Programming
AMKSS Career Conference 2015: ProgrammingMelvin Zhang
 
Building a state of the art AI to play Magic: The Gathering
Building a state of the art AI to play Magic: The GatheringBuilding a state of the art AI to play Magic: The Gathering
Building a state of the art AI to play Magic: The GatheringMelvin Zhang
 
Efficient Selectivity and Backup Operators in Monte-Carlo Tree Search
Efficient Selectivity and Backup Operators in Monte-Carlo Tree SearchEfficient Selectivity and Backup Operators in Monte-Carlo Tree Search
Efficient Selectivity and Backup Operators in Monte-Carlo Tree SearchMelvin Zhang
 
Quest for the optimal algorithm
Quest for the optimal algorithmQuest for the optimal algorithm
Quest for the optimal algorithmMelvin Zhang
 
Playing Games by Throwing Dice
Playing Games by Throwing DicePlaying Games by Throwing Dice
Playing Games by Throwing DiceMelvin Zhang
 
Becoming a better problem solver: a CS perspective
Becoming a better problem solver: a CS perspectiveBecoming a better problem solver: a CS perspective
Becoming a better problem solver: a CS perspectiveMelvin Zhang
 
Ortholog assignment
Ortholog assignmentOrtholog assignment
Ortholog assignmentMelvin Zhang
 
Building pipelines with Make
Building pipelines with MakeBuilding pipelines with Make
Building pipelines with MakeMelvin Zhang
 
Opportunities in STEM
Opportunities in STEMOpportunities in STEM
Opportunities in STEMMelvin Zhang
 

More from Melvin Zhang (11)

Functional programming from first principles
Functional programming from first principlesFunctional programming from first principles
Functional programming from first principles
 
Binary Lambda Calculus and Combinatory Logic
Binary Lambda Calculus and Combinatory LogicBinary Lambda Calculus and Combinatory Logic
Binary Lambda Calculus and Combinatory Logic
 
AMKSS Career Conference 2015: Programming
AMKSS Career Conference 2015: ProgrammingAMKSS Career Conference 2015: Programming
AMKSS Career Conference 2015: Programming
 
Building a state of the art AI to play Magic: The Gathering
Building a state of the art AI to play Magic: The GatheringBuilding a state of the art AI to play Magic: The Gathering
Building a state of the art AI to play Magic: The Gathering
 
Efficient Selectivity and Backup Operators in Monte-Carlo Tree Search
Efficient Selectivity and Backup Operators in Monte-Carlo Tree SearchEfficient Selectivity and Backup Operators in Monte-Carlo Tree Search
Efficient Selectivity and Backup Operators in Monte-Carlo Tree Search
 
Quest for the optimal algorithm
Quest for the optimal algorithmQuest for the optimal algorithm
Quest for the optimal algorithm
 
Playing Games by Throwing Dice
Playing Games by Throwing DicePlaying Games by Throwing Dice
Playing Games by Throwing Dice
 
Becoming a better problem solver: a CS perspective
Becoming a better problem solver: a CS perspectiveBecoming a better problem solver: a CS perspective
Becoming a better problem solver: a CS perspective
 
Ortholog assignment
Ortholog assignmentOrtholog assignment
Ortholog assignment
 
Building pipelines with Make
Building pipelines with MakeBuilding pipelines with Make
Building pipelines with Make
 
Opportunities in STEM
Opportunities in STEMOpportunities in STEM
Opportunities in STEM
 

Recently uploaded

Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)Roberto Bettazzoni
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Maxim Salnikov
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Flutter Agency
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmuxevmux96
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Conceptsthomashtkim
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanNeo4j
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIInflectra
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphNeo4j
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletAndrea Goulet
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfWSO2
 
Rapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and InsightsRapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and Insightsrapidoform
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxNeo4j
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMarkus Moeller
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit MilanNeo4j
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Clinic
 

Recently uploaded (20)

Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmux
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Rapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and InsightsRapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and Insights
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 

Optimize all the things with MiniZinc