{"id":5263,"date":"2014-04-25T09:00:21","date_gmt":"2014-04-25T13:00:21","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5263"},"modified":"2016-05-17T21:13:59","modified_gmt":"2016-05-18T01:13:59","slug":"clean-up-your-simulink-model","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2014\/04\/25\/clean-up-your-simulink-model\/","title":{"rendered":"Clean Up Your Simulink Model"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\">Greg's<\/a> pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45670-bot\">BOT<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/2169\">Joerg Buchholz<\/a>.\r\n\r\nHave you ever received a Simulink model that looked more like a bowl of spaghetti than a useful diagram where you could tell\r\nwhat was going on? Better yet, have you built such a Simulink model, and then regretted it later when you tried to make a\r\nchange to the model?\r\n\r\nIf this is the case, I bet you wished there was a button you could press to clean up and reorganize the model so it would\r\nbe easier to read and understand.\r\n\r\nJoerg's entry, BOT, attempts to provide such a solution. Plus it has a nice App and animation feature to go with it.\r\n\r\n<b>Organize Layout of Simulink Model<\/b>\r\n\r\nIn essence, BOT works by resizing blocks according to number of ports, move blocks, and adjust signal lines to simplify the\r\ninterpretation of the Simulink model diagram:\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/potw_cleanupsimulinkmodels\/modelAnimationTrial.gif\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nThis is a screen capture of the animation feature provided by BOT. The animation gives a nice sense of progress to the results\r\nof the optimization. For the screen capture, I sped up the video by 3x.\r\n\r\nThe various options for the block diagram layout optimization routine are made accessible through a nice, simple user interface:\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/potw_cleanupsimulinkmodels\/botUI.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\n<b>BOT is an excellent attempt at a hard problem<\/b>\r\n\r\nOptimizing the layout of a block diagram, especially for visual interpretation is a non-trivial task. There are a large number\r\nof competing constraints, with potentially different priorities. Not to mention the difficulty in determining quantitatively\r\nif the diagram is in fact \"cleaned up\".\r\n\r\nFor example, the elimination of overlapping blocks might have higher priority than intersecting lines. But should elimination\r\nof co-linear Simulink signals (i.e. Simulink signals that overlap by laying one on top of another) have higher or lower priority\r\nthan elimination of overlapping blocks?\r\n\r\nShould block size be a function of just the number of ports, or also the size of the blocks from which the signals originated?\r\nThis might make the diagram simpler to interpret, but could result in model diagrams exploding in the screen area.\r\n\r\n<b>Is BOT always successful?<\/b>\r\n\r\nNo. In short BOT cannot always improve a Simulink model's layout. I tried a couple of models that I downloaded from the File\r\nExchange, and BOT had a tough time resolving line crossings which would involve moving blocks from one side of a Simulink\r\nsignal line to the other side.\r\n\r\nHowever, this entry has inspired me personally. I have spent long hours, way more than one probably should, thinking about\r\nthis type of problem: how to measure things like how understandable a block diagram is; how the various constraints should\r\nbe weighted; etc.\r\n\r\nA few others have looked at this too. In general our customers have built their own tools to deal with this class of problem.\r\n\r\n<b>Comments<\/b>\r\n\r\nThis is already a great start. Anyone up for a challenge to extend it by adding some of the priorities I talked about above?\r\nOr simply give this a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5263#respond\">here<\/a> and leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45670-bot#comments\">comment<\/a> for Joerg.\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_ae140ff286264163a07dfbd5a9ab64cf() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='ae140ff286264163a07dfbd5a9ab64cf ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' ae140ff286264163a07dfbd5a9ab64cf';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = '';\r\n        copyright = 'Copyright 2014 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\r\n\r\n\r\n\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae R2014a<\/p>\r\n\r\n<\/div>\r\n<!--\r\nae140ff286264163a07dfbd5a9ab64cf ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620 % Greg's> pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45670-bot BOT> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/2169 Joerg % Buchholz>.\r\n%\r\n% Have you ever received a Simulink model that looked more like a bowl of\r\n% spaghetti than a useful diagram where you could tell what was going on?\r\n% Better yet, have you built such a Simulink model, and then regretted it\r\n% later when you tried to make a change to the model?\r\n%\r\n% If this is the case, I bet you wished there was a button you could press\r\n% to clean up and reorganize the model so it would be easier to read and\r\n% understand.\r\n%\r\n% Joerg's entry, BOT, attempts to provide such a solution. Plus it has a\r\n% nice App and animation feature to go with it.\r\n%\r\n% *Organize Layout of Simulink Model*\r\n%\r\n% In essence, BOT works by resizing blocks according to number of ports,\r\n% move blocks, and adjust signal lines to simplify the interpretation of\r\n% the Simulink model diagram:\r\n%\r\n% <<modelAnimationTrial.gif>>\r\n%\r\n% This is a screen capture of the animation feature provided by BOT. The\r\n% animation gives a nice sense of progress to the results of the\r\n% optimization.  For the screen capture, I sped up the video by 3x.\r\n%\r\n% The various options for the block diagram layout optimization routine are\r\n% made accessible through a nice, simple user interface:\r\n%\r\n% <<botUI.png>>\r\n%\r\n% *BOT is an excellent attempt at a hard problem*\r\n%\r\n% Optimizing the layout of a block diagram, especially for visual\r\n% interpretation is a non-trivial task. There are a large number of\r\n% competing constraints, with potentially different priorities. Not to\r\n% mention the difficulty in determining quantitatively if the diagram is in\r\n% fact \"cleaned up\".\r\n%\r\n% For example, the elimination of overlapping blocks might have higher\r\n% priority than intersecting lines. But should elimination of co-linear\r\n% Simulink signals (i.e. Simulink signals that overlap by laying one on top\r\n% of another) have higher or lower priority than elimination of overlapping\r\n% blocks?\r\n%\r\n% Should block size be a function of just the number of ports, or also the\r\n% size of the blocks from which the signals originated? This might make the\r\n% diagram simpler to interpret, but could result in model diagrams\r\n% exploding in the screen area.\r\n%\r\n% *Is BOT always successful?*\r\n%\r\n% No. In short BOT cannot always improve a Simulink model's layout. I tried\r\n% a couple of models that I downloaded from the File Exchange, and BOT had\r\n% a tough time resolving line crossings which would involve moving blocks\r\n% from one side of a Simulink signal line to the other side.\r\n%\r\n% However, this entry has inspired me personally. I have spent long hours,\r\n% way more than one probably should, thinking about this type of problem:\r\n% how to measure things like how understandable a block diagram is; how the\r\n% various constraints should be weighted; etc.\r\n%\r\n% A few others have looked at this too. In general our customers have built\r\n% their own tools to deal with this class of problem.  At least one has\r\n% <https:\/\/www.mathworks.com\/automotive\/mac2007\/proceedings\/day1\/papers\/9_mate_approach.pdf % published> their results.\r\n%\r\n% *Comments*\r\n%\r\n% This is already a great start. Anyone up for a challenge to extend it by\r\n% adding some of the priorities I talked about above? Or simply give this a\r\n% try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=5263#respond here> and leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45670-bot#comments % comment> for Joerg.\r\n##### SOURCE END ##### ae140ff286264163a07dfbd5a9ab64cf\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/potw_cleanupsimulinkmodels\/modelAnimationTrial.gif\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n\r\nGreg's pick this week is BOT by Joerg Buchholz.\r\n\r\nHave you ever received a Simulink model that looked more like a bowl of spaghetti than a useful diagram where you could tell\r\nwhat was going on?... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2014\/04\/25\/clean-up-your-simulink-model\/\">read more >><\/a><\/p>","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5263"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=5263"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5263\/revisions"}],"predecessor-version":[{"id":7268,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5263\/revisions\/7268"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}