{"_id":"56a97494ca491e0d00eb8aaa","version":{"_id":"56a83b989ec7660d002e07c1","project":"56a83b979ec7660d002e07be","__v":9,"createdAt":"2016-01-27T03:38:00.333Z","releaseDate":"2016-01-27T03:38:00.333Z","categories":["56a83b989ec7660d002e07c2","56a83c282036420d002d21e1","56a96de8f834950d0037b35a","56a9706013a69a0d00a778c3","56a970ec2d8fd90d0036eec7","56a971a62bb3910d000ee934","56a973372d8fd90d0036eece","56a978dc2bb3910d000ee93f","571d5ae118b3c10e003e55cd"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Beta","version_clean":"1.0.0","version":"1.0"},"user":"56a83a6070a9440d00ef5ef8","__v":9,"category":{"_id":"56a9706013a69a0d00a778c3","project":"56a83b979ec7660d002e07be","pages":["56a970a1cc0f740d005bc15d","56a97494ca491e0d00eb8aaa","56a98367257fbc0d00d47627"],"version":"56a83b989ec7660d002e07c1","__v":3,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-28T01:35:28.486Z","from_sync":false,"order":3,"slug":"mathematical-model","title":"Mathematical Model"},"parentDoc":null,"githubsync":"","project":"56a83b979ec7660d002e07be","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-28T01:53:24.954Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"<div class=\"corner-ribbon top-left sticky blue\"><a style=\"color: white;\" href=\"https://pathfinder.readme.io/blog/pathfinder-now-in-public-beta\">Public Beta!</a></div>\n\nThis document describes how the [Objective Function DSL](doc:objective-function-dsl) is compiled into JuMP Julia macros. For now it simply consists of several DSL examples and the generated Julia code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"sense: min\\ncontext:\\n    method: sum\\n    for:\\n        t: transport\\nquantity: t.distance\",\n      \"language\": \"yaml\"\n    },\n    {\n      \"code\": \":::at:::defVar(model, _value, Int)\\n@addConstraint(model, _value == sum{distance[t],t=TA})\\n@setObjective(model, Min, _value)\",\n      \"language\": \"julia\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"sense: min\\ncontext:\\n    method: sum\\n    for:\\n        c1: commodity\\n        c2: commodity\\nquantity:\\n    absolute_value:\\n        - subtract:\\n            - subtract:\\n                - c1.dropoff_time\\n                - c1.request_time\\n            - subtract:\\n                - c2.dropoff_time\\n                - c2.request_time\",\n      \"language\": \"yaml\"\n    },\n    {\n      \"code\": \"@defVar(model, _value, Int)\\n@defVar(model, _tmp1[DA,DA], Int)\\n@defVar(model, _tmp2[DA,DA], Int)\\n@defVar(model, _tmp3[DA,DA], Int)\\n@defVar(model, _tmp4[DA,DA], Int)\\n@defVar(model, pos_tmp4[DA,DA] >= 0, Int)\\n@defVar(model, neg_tmp4[DA,DA] >= 0, Int)\\nfor c1 in DA\\nfor c2 in DA\\n@addConstraint(model, _tmp1[c1,c2] == dropoff_time[c1] - parameters[\\\"request_time\\\"][c1])\\n@addConstraint(model, _tmp2[c1,c2] == dropoff_time[c2] - parameters[\\\"request_time\\\"][c2])\\n@addConstraint(model, _tmp3[c1,c2] == _tmp1[c1,c2] - _tmp2[c1,c2])\\n@addConstraint(model, _tmp4[c1,c2] == pos_tmp4[c1,c2] + neg_tmp4[c1,c2])\\n@addConstraint(model, _tmp3[c1,c2] == pos_tmp4[c1,c2] - neg_tmp4[c1,c2])\\n@addConstraint(model, _value >= _tmp4[c1,c2])\\nend\\nend\",\n      \"language\": \"julia\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"objective-function-dsl-1","type":"basic","title":"DSL Compilation"}
<div class="corner-ribbon top-left sticky blue"><a style="color: white;" href="https://pathfinder.readme.io/blog/pathfinder-now-in-public-beta">Public Beta!</a></div> This document describes how the [Objective Function DSL](doc:objective-function-dsl) is compiled into JuMP Julia macros. For now it simply consists of several DSL examples and the generated Julia code. [block:code] { "codes": [ { "code": "sense: min\ncontext:\n method: sum\n for:\n t: transport\nquantity: t.distance", "language": "yaml" }, { "code": "@defVar(model, _value, Int)\n@addConstraint(model, _value == sum{distance[t],t=TA})\n@setObjective(model, Min, _value)", "language": "julia" } ] } [/block] [block:code] { "codes": [ { "code": "sense: min\ncontext:\n method: sum\n for:\n c1: commodity\n c2: commodity\nquantity:\n absolute_value:\n - subtract:\n - subtract:\n - c1.dropoff_time\n - c1.request_time\n - subtract:\n - c2.dropoff_time\n - c2.request_time", "language": "yaml" }, { "code": "@defVar(model, _value, Int)\n@defVar(model, _tmp1[DA,DA], Int)\n@defVar(model, _tmp2[DA,DA], Int)\n@defVar(model, _tmp3[DA,DA], Int)\n@defVar(model, _tmp4[DA,DA], Int)\n@defVar(model, pos_tmp4[DA,DA] >= 0, Int)\n@defVar(model, neg_tmp4[DA,DA] >= 0, Int)\nfor c1 in DA\nfor c2 in DA\n@addConstraint(model, _tmp1[c1,c2] == dropoff_time[c1] - parameters[\"request_time\"][c1])\n@addConstraint(model, _tmp2[c1,c2] == dropoff_time[c2] - parameters[\"request_time\"][c2])\n@addConstraint(model, _tmp3[c1,c2] == _tmp1[c1,c2] - _tmp2[c1,c2])\n@addConstraint(model, _tmp4[c1,c2] == pos_tmp4[c1,c2] + neg_tmp4[c1,c2])\n@addConstraint(model, _tmp3[c1,c2] == pos_tmp4[c1,c2] - neg_tmp4[c1,c2])\n@addConstraint(model, _value >= _tmp4[c1,c2])\nend\nend", "language": "julia" } ] } [/block]