Full text
Universidade do Minho Escola de Engenharia Hugo Afonso da Gião LPBlocks - A Block-based Language for Linear Programming January, 2022
Universidade do Minho Escola de Engenharia Hugo Afonso da Gião LPBlocks - A Block-based Language for Linear Programming Master’s Dissertation Master’s in Informatics Engineering Work supervised by Jácome Cunha Rui Pereira January, 2022
STATEMENT OF INTEGRITY I hereby declare having conducted this academic work with integrity. I confirm that I have not used plagiarism or any form of undue use of information or falsification of results along the process leading to its elaboration. I further declare that I have fully acknowledged the Code of Ethical Conduct of the Universidade do Minho. , (Location) (Date) (Hugo Afonso da Gião)
Despacho RT - 31 /2019 - Anexo 3 Declaração a incluir na Tese de Doutoramento (ou equivalente) ou no trabalho de Mestrado DIREITOS DE AUTOR E CONDIÇÕES DE UTILIZAÇÃO DO TRABALHO POR TERCEIROS Este é um trabalho académico que pode ser utilizado por terceiros desde que respeitadas as regras e boas práticas internacionalmente aceites, no que concerne aos direitos de autor e direitos conexos. Assim, o presente trabalho pode ser utilizado nos termos previstos na licença abaixo indicada. Caso o utilizador necessite de permissão para poder fazer um uso do trabalho em condições não previstas no licenciamento indicado, deverá contactar o autor, através do RepositóriUM da Universidade do Minho. Licença concedida aos utilizadores deste trabalho Atribuição CC BY https://creativecommons.org/licenses/by/4.0/
Acknowledgements I would like to thank the Univesity of Minho and HASLab/INESC TEC, my advisors Jácome Cunha and Rui Pereira for offering their guidance and experience, as well as all the volunteers that participated in our study and every person that helped in this project. iii
Abstract Linear programming is a mathematical optimization technique used in numerous fields including mathematics, economics, and computer science, with numerous industrial contexts, including solving optimization problems such as planning routes, allocating resources, and creating schedules. As a result of its wide breadth of applications, a considerable amount of its user base lacks programming knowledge and experience and thus often resorts to using graphical software such as Microsoft Excel. However, despite its popularity amongst less technical users, the methodologies used by these tools are often ad-hoc and prone to errors. Block-based languages have been successfully used to aid novice programmers and even children in programming. Thus, we created a block-based programming language termed LPBlocks that allows users to create linear programming models using data contained in spreadsheets. This language guides the users to write syntactically and semantically correct programs and thus aids them in a way that current languages do not. We have also implemented a web application where users can define linear programming models, reactively see their mathematical representation and execute them to obtain the optimization values for the variables defined by the users. To assess the applicability of LPBlocks we used it to successfully express numerous and varied linear programming problems. Furthermore, we designed and ran a qualitative empirical study to understand the experience our tool and language brings to users from various backgrounds. Although we see differences amongst the users, most of them were able to model several problems using LPBlocks. Keywords: Linear programming, Operations research, Optimization, Block-based languages, Visual languages, Blockly iv
Resumo Programação linear é um conjunto de técnicas de otimização matemática utilizada em várias áreas estas incluem matemática, economia, ciências da computação e usos em contextos industriais, incluindo planear rotas, alocar recursos e planear horários. Como resulta das suas aplicações variadas uma grande quantidade dos seus utilizadores não possuem conhecimentos de programação e por isso utilizam software gráfico como o Microsoft Excel. Apesar da sua popularidade este software utiliza metodologias ad-hoc e propicias a erros. As linguagem de programação por blocos tem surgido nos últimos anos com o intuito de ajudar programadores iniciantes, tendo mesmo aplicações no ensino de crianças. Sendo assim nos criamos uma linguagem de programação pro blocos que utiliza dados contidos em folhas de calculo para criar modelos de programação linear chamada LPBlocks. Esta linguagem guia utilizadores na criação de modelos semanticamente e sintaticamente corretos. Para avaliar a validade de LPBlocks nos implementamos vários problemas utilizando a mesma. Posteriormente implementamos esta linguagem e utilizamo-la num estudo com utilizadores de vários níveis de experiência. Depois utilizamos a informação recolhida durante o estudo para avaliar LPBlocks e propor melhorias. Palavras-chave: Programação linear, Investigação operacional, Linguagens de blocos, Linguagens visuais, Blockly … v
Contents List of Figures ix List of Tables xi Listings xii List of Algorithms xiii 1 Introduction 1 1.1 Motivation ..................................... 1 1.2 Our Approach .................................... 2 1.3 Research questions ................................. 2 1.4 Contributions .................................... 3 1.5 Document organization ............................... 3 2 State of the art 5 2.1 Formulating a linear programming problem ..................... 5 2.2 Operations research tooling ............................. 7 2.2.1 Excel .................................... 7 2.2.2 SAS/OR .................................. 9 2.2.3 NCSS ................................... 9 2.2.4 MATLAB .................................. 10 2.2.5 LINGO and What’sBest! .......................... 12 2.2.6 Summary and comparisons ........................ 12 2.3 Projects involving visual languages and linear programming ............. 15 2.3.1 A graphics interface for linear programming ................ 15 2.3.2 Creating a GUI Solver for Linear Programming Models in MATLAB . . . . . . 16 2.3.3 gLPS: A graphical tool for the definition and manipulation of linear problems . 16 2.3.4 Two-variable Linear Programming: A Graphical Tool with mathematica . . . . 18 2.3.5 Conclusions ................................ 19 2.4 Frameworks and notable visual languages projects .................. 20 vi
CONTENTS 2.4.1 Blockly ................................... 20 2.4.2 BlockPy .................................. 20 2.4.3 MIT app Inventor .............................. 21 3 A block-based language for linear programming 23 3.1 Data structure ................................... 23 3.2 Blocks ....................................... 24 3.3 Defining variables .................................. 25 3.4 Defining constraints ................................. 26 3.5 Defining the objective function ............................ 27 4 Implementation and architecture 29 4.1 Web application ................................... 29 4.1.1 Features .................................. 31 4.1.2 Compilation process ............................ 34 4.2 Spreadsheet reading service ............................. 38 4.3 Optimization service ................................ 39 5 Language applicability 41 5.1 Vegetable mixture .................................. 41 5.2 Fruit canning plants ................................. 42 5.3 Machine allocation ................................. 43 5.4 Pharmaceutical company .............................. 45 5.5 Computer manufacturing .............................. 46 5.6 Satellite launching ................................. 47 5.7 Cargo allocation .................................. 48 5.8 Threats to validity .................................. 48 6 Empirical evaluation 50 6.1 Design ....................................... 50 6.2 Instrumentation ................................... 51 6.3 Execution ...................................... 51 6.4 Data collection ................................... 52 6.4.1 Background data .............................. 52 6.4.2 Sessions .................................. 53 6.4.3 Participants feedback ............................ 57 6.5 Analysis and conclusions .............................. 57 6.6 Threats to validity .................................. 60 7 Conclusions and future work 61 vii
Chapter 1 Introduction This chapter introduces the context of this thesis work and the problem we address (Subsection 1.1). In Subsection 1.2 we expand on our solution to the given problem. Further in Subsection 1.3 we propose several questions that we intend on answering within this work. Then in Subsection 1.4 we showcase relevant contributions from this work and in Subsection 1.5 we describe the organization of the remainder of this document. 1.1 Motivation Linear programming is a mathematical optimization technique used to find the best possible outcomes in problems specified by linear specification constraints. It originated as a discipline during the 1940s as an effort to tackle complex problems associated with wartime operations. These methods have since found uses in many areas in fields such as mathematics, computer science, business, economics, and engineering and problems such as planning, routing, scheduling, assignment, and design [23]. The versatility of linear programming in formulating all sorts of problems lends itself useful in many industrial contexts from schedule optimization to route planning. Since many of its users have little to no programming or technical knowledge, visual software such as Microsoft Excel is often the preferred tool when it comes to specifying and solving this type of problem [11]. Despite its widespread use, end users still face many obstacles when trying to define linear programming models in existing tools since they often require some knowledge of programming to achieve desired outcomes. This is the case of tools such as MATLAB1or SAS/OR2, and various libraries such as Google OR-Tools3or PuLP4. Spreadsheet software such as Excel allows users to formulate and solve both linear 1https://www.mathworks.com/products/matlab.html 2https://www.sas.com/en_us/software/or.html 3https://developers.google.com/optimization 4https://pypi.org/project/PuLP/ 1
CHAPTER 1. INTRODUCTION and non-linear optimization problems using algorithms such as simplex, generalized reduced gradient, and evolutionary algorithms [20]. Users with less technical background will probably find it easier to use this kind of software. However, similarly to other Excel tasks this methodology is also ad-hoc and could cause problems to novice users due to input errors at the moment of defining variables as well as other errors in the spreadsheet building process due to its lack of methodology. Some of the underlying problems include adding constraints and optimization function from the spreadsheet to the solver, the difficulty in visualizing the complete model, not being able to define constraints by its columns, the inability to call variables by name instead of its cell position, and lack of an interactive model and building process. Other visual tools often use spreadsheet or spreadsheet-like software with the methodologies and problems that come with that, learning linear programming also comes with some difficulties that have been previously mitigated with the use of technology [6]. Some works have used visual languages to tackle aspects of linear programming, however, the majority of them focus on the educational and teaching of mathematical aspects of linear programming [12,19]. The few existing projects focusing on the applied side of linear programming tend to be several decades old and have dated and unappealing interfaces and do not make use of recent advances in the field of visual languages and human-centered computing [13,21]. 1.2 Our Approach Numerous projects have applied visual languages to various fields of computing, generally focused on increasing accessibility of novice and non-technical users as well as teaching. A considerable amount of these languages use the Blockly framework for their implementation [17]. These languages include BlockPy [3], a web-based platform that lets the user write and run Python code using a block-based language, and Scratch [15], a block-based visual programming language and educational tool mostly targeted at children. Our approach involved creating a block-based language which we titled LPBlocks that lets users create linear programming formulations. We also implemented a highly reactive web interface possessing numerous features such as dynamic compilation, error messages, the ability to load data from spreadsheets, and run the created models. Beyond our technical work, we also performed a study to evaluate the applicability of the language and a qualitative empirical study to understand how users interact with the language and tool. This project comes as the sequence of a project aiming at the creation of visual language for the systematic creation of spreadsheets [16], initially we planned on integrating our language with the tool created by the authors but eventually decided that creating a web interface would be preferable for less technical users and the integration with Excel was not a critical aspect of our work. 1.3 Research questions Considering our motivation and goals our thesis aims to answer the following questions: 2
CHAPTER 1. INTRODUCTION •RQ1 -Can we use block-based languages to represent linear programming formulations. Currently the tools used in both education and industry to create linear programming models either require pre-existing programming knowledge, use ad-hoc methodologies, or cannot be used for formulating general models. Since linear programming has several uses, improving its process for less technical users could be beneficial in improving their productivity and capabilities. •RQ2 -Will using a block-based language and environment allow end users to express linear programming models. We intend to evaluate the created language and environment assessing the experience of users with different backgrounds. 1.4 Contributions With this work we make the following contributions: • A visual, block-based language capable of expressing linear programming problems termed LP- Blocks. • A web application that allows users to build, debug and run linear programming models using LPBlocks. The source code is available at https://github.com/h4g0/blockly-spaces and the web application at https://lpblocks.herokuapp.com/. The scientific publications associated with our work are the following: • Linear Programming Meets Block-based Languages Hugo Gião, Rui Pereira, Jácome Cunha IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC’21) [9] • Towards a Block-based Language for Linear Programming Hugo Gião, Rui Pereira, Jácome Cunha 12𝑡ℎ National Symposium of Informatics (INForum’21) [10] 1.5 Document organization To present our work, the document is organized as follows: • Chapter 2describes the state of the art when it comes to end-user tooling for linear programming, visual and block-based languages, and projects that bridge visual languages and linear programming. 3
CHAPTER 1. INTRODUCTION • Chapter 3showcases LPBlocks, a block-based language capable of expressing linear programming models. We explain how the data is received, the different blocks, and how to use them. • Chapter 4elaborates on the implementation details and compilation process for our language. We also showcase the interface of the tool we have implemented and its features. • Chapter 5discusses the applicability of our language by using it to solve a selection of problems taken from class notes and operations research textbooks. • Chapter 6presents an empirical study we executed in which the users after a brief tutorial solved several linear programming problems using our tool and then answered a survey where they shared their experiences. • Chapter 7analyzes the results of our work and proposes some possible improvements and continuation to this project. 4
Chapter 2 State of the art To give a small introduction to linear programming we start with Section 2.1, where we showcase the process of formulating a given linear programming problem using mathematical notation. We then expose a variety of tools related to our work. To do so we started by researching capable and some of the more user-friendly tools for operations research and linear programming purposes (Section 2.2). These tools are not necessarily the most popular and widely used in industry for the purposes above stated and are not necessarily the most widely used since the more programmatic methodology is often preferred. In the same Section, after exposing the different solutions and some of their methodologies, we proceed to do a comparison and comment on which would be the most appropriate for different user bases according to different aspects such as price and features and then discuss some of their shortcomings and possible solutions. Then in Section 2.3 we present some works that apply visual languages and human-centered computing to the field of linear programming. The projects approached in this Section focus on both educational and industrial applications of linear programming. Some of them aim to help novice users use and learn linear programming and others aim at seasoned users. In Section 2.4 we present some existing visual languages projects. These projects tackle various development and computing areas such as data science, application creation, and spreadsheet manipulating with applications in both enterprise and education markets. We present such works as they are related to our solution, which is a visual language. 2.1 Formulating a linear programming problem There are many steps involved in the linear programming workflow, the first of them being understanding the problem at hand, what value does the user want to know and what this value depends upon. The next steps include defining the decision variables according to the problem, writing an objective function, 5
CHAPTER 2. STATE OF THE ART defining the constraints, writing the constraints in terms of decision variables, and adding non-negativity to the constraints [1]. In this Section, we will use an example taken from an operations research textbook [5] to illustrate the process of creating linear programming formulations using mathematical notation. In this problem, a manufacturer of freeze-dried vegetable mixtures needs to respect certain requirements when it comes to each mixture composition. Each mixture is to be composed of beans, corn, broccoli, cabbage, and potatoes. The mixture needs to contain (by weight) at most 40% beans and at most 32% potatoes. The mixture should contain at least 5 grams of iron, 36 grams of phosphorus, and 28 grams of calcium. The nutrients in each vegetable and the costs can be seen in Table 2.1. Vegetables Iron Phosphorus Calcium Cost per pound Beans 0.5 10 200 20 Corn 0.5 20 280 18 Broccoli 1.2 40 800 32 Cabbage 0.3 30 420 28 Potatoes 0.4 50 360 16 Table 2.1: Data for the given problem The first step to model this problem as a linear programming one is to create a set of variables that can be used to express the restrictions and objective described. We create the variables 𝑥1,𝑥2,𝑥3,𝑥4, and 𝑥5as the number of pounds of beans, corn, broccoli, cabbage, and potatoes in each mixture. After creating the variables we create the following constraints: • The percentage of beans in the mixture must be less than 40% of the total and the percentage of potatoes less than 32%. Since the total weight of the mixture is represented as the sum of the variables we get the following constraints in mathematical notation: 𝑥1<=0.4(𝑥1+𝑥2+𝑥3+𝑥4+𝑥5)(2.1) 𝑥5<=0.4(𝑥1+𝑥2+𝑥3+𝑥4+𝑥5)(2.2) • To achieve the required level of nutrients, for each of the nutrients (iron, phosphorus, and calcium, respectively) we need to take into account the amount of each of them in the different vegetables and use this information to generate the following constraints: 0.5𝑥1,+0.5𝑥2+1.2𝑥3+0.3𝑥4+0.4𝑥5>5000 (2.3) 10𝑥1,+20𝑥2+40𝑥3+30𝑥4+50𝑥5>36000 (2.4) 200𝑥1,+280𝑥2+800𝑥3+420𝑥4+360𝑥5>28000 (2.5) • We also need to guarantee non-negativity by specifying that each of our variables is greater than 0. 6
CHAPTER 2. STATE OF THE ART 𝑥1>=0(2.6) 𝑥2>=0(2.7) 𝑥3>=0(2.8) 𝑥4>=0(2.9) 𝑥5>=0(2.10) Finally we define our objective function. Since our goal is to minimize costs and since the cost of the mixture is given by the sum each of our variables multiplied by its cost per pound we get the following objective: 𝑚𝑖𝑛𝑖𝑚𝑖𝑧𝑒(20𝑥1+18𝑥2+32𝑥3+28𝑥4+16𝑥5)(2.11) All these equations can then be expressed in a linear programming solver to get the solution for each of the variables, thus giving the final solution. In the following Sections we describe some of the existing tools to do so. 2.2 Operations research tooling 2.2.1 Excel Microsoft Excel1is a spreadsheet software developed by Microsoft with support for various platforms such as Windows,macOS,Android, and iOS. It includes many features related to manipulating and analyzing spreadsheets as well as various features related to business, engineering, and data analytics. Excel is closed source and paid for all users except students2. Excel allows for formulating and solving linear programming problems using its add-in solver. Using Excel for this task comes with some caveat, namely the methodology used for adding the constraints, variables, and the objective is ad-hoc, its interface not being user friendly, not having predefined templates for specific use cases and the solver not being native to Excel. To be able to solve linear programming problems in Excel users need to follow several steps involved in downloading the solver add-in. Having the solver add-in installed we can move to the next step. For demonstration purposes we will be using a tablet manufacturing example. This problem states that a tablet manufacturer has to optimize the production of two tablet models to maximize profits. This example was sourced from youtube [14]. To solve this problem we first define the problem variables, constraints, and optimization function inside an Excel spreadsheet as seen in Figure 2.1.A In this case, we define the requirements in terms of 1https://office.live.com/start/excel.aspx 2https://www.microsoft.com/en-us/microsoft-365/p/excel/cfq7ttc0k7dx?activetab=pivot% 3aoverviewtab 7
CHAPTER 2. STATE OF THE ART Labour hours,Chip sets and Electronic components for each of the models as well as their availability. We then define two variables, one called Pro Model units and another called Mini Model units, indicating the number of units of each model to be produced. After we define the number of units for each of the requirements as the requirements for each of the model multiplied by the number of produced units, we then define the constant Unit Profit for both models and the objective function Total profit defined as being the sumproduct of each of the units with its profit. B A Figure 2.1: Results outputted from the solver into the spreadsheet. After defining the problem inside the Excel spreadsheet we open the solver add-in. We then are prompted with a window in which we add the different variables, constants, objective function and choose from one of the three available solvers as seen in Figure 2.2. Figure 2.2: Adding variables, constraints and defining the objective in the Excel solver. 8
CHAPTER 2. STATE OF THE ART After solving our problem the Excel solver add-in outputs both the solutions seen in Figure 2.1.B and a report detailing the problem specification as well as some of the steps and details about the algorithm used, seen in Figure 2.3. Figure 2.3: Example of an Excel linear programming report 2.2.2 SAS/OR The SAS/OR software allows the use of various state of the art optimization, simulation, and scheduling algorithms and software. User interfaces and functionalities vary greatly for the different SAS/OR features 3. For some tasks such as Mathematical optimization users have access to a algebraic language, however SAS/OR provides users with a graphical interface for some specific optimization tasks such as Discrete event simulation and Project and resource scheduling. This software also boasts state of the art and optimized parallel algorithms. This software is used across various industries and companies such as Nestlé,Volvo, and Honda. SAS/OR is paid and closed source with a free trying period and discounted or free for educational purposes4. 2.2.3 NCSS NCSS is a statistical and graphical program with linear and mixed integer programming capabilities. It uses Tableau or Bounds for data visualization and analysis5. The NCCSS software has many use cases and features for operations research, including solving linear programming and being equipped to solve more specific problems such as Mixed Integer Programming,Assignment,Maximum Flow To solve linear programming problems using the NCSS software users must define the variables in a spreadsheet as seen in figure 2.4a, and subsequently indicate to the solver which are the columns that represent the variables, constraints, and logic as seen in 2.4b. When compared with Excel,NCSS uses a more structured approach seeing that all variables, logic columns and constraints must be defined in specific columns and does not require that the users build the model by selecting the data in the file using the mouse. The reports seen in 2.4c generated by the solver are similar to the ones generated by Excel. 3https://www.sas.com/pt_pt/software/or.html#m=features 4https://www.sas.com/pt_pt/software/how-to-buy/request-price-quote.html 5https://www.ncss.com/software/ncss/operations-research-in-ncss/#Technical 9
CHAPTER 2. STATE OF THE ART Despite improving on the Excel methodology, the NCSS methodology could be improved with a more interactive and user-friendly approach to the problem definition. Pricing wise NCSS is paid for all users but possesses a free trial6. This software is also closed source. 2.2.4 MATLAB MATLAB is a software tool supporting a visual environment created for iterative analysis and design process and a programming language that expresses matrices and arrays directly as well as a live editor and the capability to output text, graphics, and formatted notebooks7. The main appeal behind MATLAB stands from it requiring lower configuration and setup compared to other programming environments. Other factors distinguishing MATLAB from the alternatives stand from its performance, state of the art algorithms and scalability, its ease of integration, and industry-focused features such as its support for model-based design and easy deployment with business systems. One of its biggest setbacks stands from its pricing, at time of writing it does not have any free tier, MATLAB is closed source as well7. Users can use MATLAB to model and solve linear programming problems using the 𝑙𝑖𝑛𝑝𝑟𝑜𝑔 function. Users can use this function by expressing both variables and constants in a matrix form. As an example, the following inequalities constraint 𝑥(1) + 𝑥(3) ≤ 2(2.12) 𝑥(1) + 𝑥(2)/4≤1(2.13) 𝑥(1) − 𝑥(2) ≤ 2(2.14) −𝑥(1)/4−𝑥(2) ≤ 1(2.15) −𝑥(1) − 𝑥(2) ≤ −1(2.16) −𝑥(1) + 𝑥(2) ≤ 2(2.17) can be expressed in MATLAB in the following way: 1A=[11 21 1/4 31 -1 4-1/4 -1 5-1 -1 6-1 1]; 7 8b=[2121-12]; After defining the inequalities constraints, the next step is to define the objective function. For this example, the following function will be used: −𝑥(1) − 𝑥(2)/3(2.18) 6https://www.ncss.com/online-store/ 7https://www.mathworks.com/products/matlab.html 10
CHAPTER 2. STATE OF THE ART Figure 2.7: LpSolver graphical interface creating a formulation with output for all iterations Figure 2.8: LpSolver graphical interface with final solution output modeling language but also an integrated software system for the creation, modification, and running of linear programming models. Contrary to other projects presented in this Subsection gLPS was created for experts capable of formulating linear programming models algebraically. The author’s name LPForm (Subsection 2.3.1) as being one language focused on improving linear programming for non-experts. The symbolism used by gLPS is a direct translation of the algebraic notation, a choice whose authors assert restricts the potential users of gLPS. The authors justify this choice by claiming that this notation would be a more natural approach 17
CHAPTER 2. STATE OF THE ART Figure 2.9: LpSolver graphical solution to operations research specialists. When creating a restriction using gLPS, users are presented with an interface as seen in Figure 2.10. Using this interface one can drag, drop, and connect different components to create a linear programming model. Figure 2.10: gLPS graphical interface 2.3.4 Two-variable Linear Programming: A Graphical Tool with mathematica Previous work introduced GLP-Tool, a graphical interface designed to help users to understand fundamental concepts of linear programming [19]. The author’s goal is to leverage active learning to increase student 18
CHAPTER 2. STATE OF THE ART engagement during the learning process. This tool is a dynamic, interactive, and visual tool that allows solving user-defined linear programming problems with two variables. In particular, the user can explore different objective functions and constraint sets, obtain graphical and numerical information on optimal solutions and intuitively perform post-optimal and sensitivity analysis. The author’s focus is clearly on education and teaching the mathematical component behind linear programming and the author justifies some of their choices on classroom requirements. The interface shown in Figure 2.11 lets the users input the objective and constraints by using selection and sliding inputs, it allows for the definition of non-negativity by choosing the option in the variable, choosing the values of the constants using a sliding option as well as the variables in the objective and constraints. Users can also choose to maximize or minimize the objective. Users can then visualize the feasible area and solution. Figure 2.11: GUI linear programming interface for MATLAB 2.3.5 Conclusions Overall we found that the projects referenced in this Section either have a mathematical approach to linear programming and its methods and do not offer business-focused features like Excel does by allowing users to work with data to create the formulations. This is seen in Subsections 2.11 and 2.3.2. Or despite focusing on similar goals to us, their projects possess outdated and not very intuitive interfaces, this is seen in Subsections 2.3.1 and 2.3.3. Considering the above we believe that taking inspiration from projects that use block-based languages for various other computing tasks could be useful to tackle our problem. 19
CHAPTER 2. STATE OF THE ART 2.4 Frameworks and notable visual languages projects 2.4.1 Blockly Blockly (whose interface can be seen in Figure 2.12) is a google created library created to build visual applications that output syntactically correct code. This library is written in pure JavaScript, is 100% clientside and without server-side dependencies, can be used with all major browsers, and is highly customizable and extendable10. Various projects have been built using this technology, having found success particularly in the educational space. These applications include Blockly Games11, code.org12, MIT App Inventor13 and BlockPy14. The creation of this library was greatly influential to the field of visual programming languages, not only due to the projects that were built using it, but as well as the insights gained into the difficulties and mistakes made when creating visual programming languages [8] which can be helpful in any project involving block-based languages. Figure 2.12: A simple Blockly program. 2.4.2 BlockPy The BlockPy (whose interface can be seen in Figure 2.13) project is a web-based, open-access Python programming environment made for introductory programming and data science education. This project 10https://developers.google.com/blockly 11https://blockly.games/ 12https://code.org/ 13https://appinventor.mit.edu/ 14https://think.cs.vt.edu/blockpy/ 20
CHAPTER 2. STATE OF THE ART came about due to the increasing need that professionals and non-computer science students feel to learn computer science related skills and due to the contextualization of introductory computer science education focusing mostly on game design and media computation thus alienating potential learners due to a perceived pointlessness to their professional activity. Since data science skills such as data processing are widely needed across a variety of fields the subject is more appealing to users from business or other technical fields wanting to change careers than other computing fields [3]. Figure 2.13: Hello World program using the BlockPy interface The choice of Python for this educational tool was because of its explicit syntax, strong support for data science libraries such as pandas, Matplotlib, and scikit-learn. Despite its ease of use when compared with other computer languages, using an intermediate visual language was an improvement for the users of the study. This was found to improve the usability of the language for novice programmers. One feature that distinguishes BlockPy from other projects allowing users to program in Python using visual languages is the possibility of freely oping between text and visual programming. This feature was found to improve the transition process between the two types of languages [2]. Accessibility is one of BlockPy’s project goals. For this reason BlockPy is an easily accessible webbased platform, all of its code is open source and leverages an array of open-source libraries. The visual language portion of this project was done using the Blockly library [3]. 2.4.3 MIT app Inventor The MIT App Inventor, whose user interface can be seen in figure 2.14, is an educational platform that uses android app development to teach introductory computer science concepts. This concept was born from the observation that smartphones play an intrinsic role in our everyday lives. However the majority of people do not understand how the technology they use works. This project tries to solve this problem by providing a more user-friendly approach to building smartphone apps. The interface uses a drag and drop approach for different components and the Blockly library for the program logic [18]. This project’s contributions to the user interface and visual programming fields stem from the realworld context and applications instead of more traditional programming aspects such as loops, arrays, 21
CHAPTER 2. STATE OF THE ART Figure 2.14: Mit app Inventor user interface. operators, and conditionals [18]. 22
C h a p t e r 3 A block-based language for linear programming In this Chapter we introduce our proposed language LPBlocks. We will describe how LPBlocks processes the data, which blocks were designed, and how to define the variables, constraints, and linear programming model’s objective. Additionally, to make it easier for the reader to understand the language constructs and format, we will use a running example featured in a Master of Business Administration (MBA) exam [4]. This example problem aims to increase the profit of deliveries by airplanes. The problem statement provides values for the weight and space capacity of three different airplane’s compartments (front, rear, and center) and maximum values for the weight, volume, and profit for four different cargoes (C1, C2, C3, and C4) as seen in Figure 3.1. Figure 3.1: Input data for the running example problem 3.1 Data structure Our language requires the input data to follow a specific structure. This structure allows for the definition of index columns (as seen highlighted in red in Figure 3.1). These are used to reference values and iterate over the data columns (in the blue columns of the same Figure) this being always associated with one index column. To distinguish between the two we assume that the data columns addressed by a given index column appear in the spreadsheet immediately after the said index column, and that different sets of index and data columns are separated by an column filled with the character #as can be seen in the 23
CHAPTER 3. A BLOCK-BASED LANGUAGE FOR LINEAR PROGRAMMING Figure (fourth column). In this case there are two sets, the first being for the three plane compartments and the second for the four types of cargo. 3.2 Blocks The building blocks of the linear programming language we propose can be seen in Figure 3.2. LPBlocks includes: •Variable blocks (seen in Figure 3.2.A): Blocks for creating single, column and matrix variables. •Operation block (seen in Figure 3.2.B): A block to construct an individual constraint or the objective. •Building blocks (seen in Figure 3.2.C): These blocks include two nesting blocks for the Variables and Constraints, a nesting block to add an individual Constraint to a Constraints block, and an Objective block to define the objective function. •Value blocks (seen in Figure 3.2.D): A set of value blocks to access the variables created before. A C D B 1 2 3 1 2 3 4 1 2 3 4 5 Figure 3.2: Building blocks for LPBlocks 24
CHAPTER 3. A BLOCK-BASED LANGUAGE FOR LINEAR PROGRAMMING 3.3 Defining variables To define a mathematical linear programming model, considering our running example, one would start by creating a set of variables iterating over the the airplane sections and the cargoes as shown in Figure 3.3.C (we refer to the problem’s original website for a more common variable naming). Since this is a very common scenario, LPBlocks includes a construct that can be used to define all these variables which we call a matrix. In Figure 3.3.B we use such a construct to create the variables for the running example. In the example, we use a matrix variable block to create a new 𝑁×𝑀matrix variable named CompartmentCargo, with 𝑁being equal to the length of the column Compartment and 𝑀to the length of the column Cargo with these columns serving as its indexes. A B C Figure 3.3: Creating an example matrix variable LPBlocks offers several options to define new variables, using the blocks seen in Figure 3.2.A respectively: • single variables through its name (as seen in Figure 3.2.A.1); • column variables defining its name and an index column for which the variable will be iterated and accessed (as seen in Figure 3.2.A.2); • matrix variables that take a name and two index columns for which they can be iterated and those values accessed ((as seen in Figure 3.2.A.3) and used in Figure 3.3.B). The process of generating the model variables is dependent on which variable blocks we used: • For the single variable block, a variable is generated with the chosen name. • For column variable blocks, an array of variables is created. • For matrix variables blocks, a matrix of variables is created (as shown in Figure 3.3.B). 25
CHAPTER 3. A BLOCK-BASED LANGUAGE FOR LINEAR PROGRAMMING 3.4 Defining constraints The second step to define the mathematical model would be to create a set of constraints, using the variables created before, and encoding the restrictions of the underlying problem. A constraint of the running example is that one “cannot pack more of each of the four cargoes than their available quantity”. The mathematical encoding would be as shown in Figure 3.4. There are four constraints, one for each cargo. For each constraint, the left-hand side of the inequality displays the sum of variables referring to the corresponding cargo (e.g. C1 for the first constraint) and for the three different airplane sections. On the right-hand side one would write the cargo weight limit. Figure 3.4: Defining constraints for the cargoes weight The first constraint in Figure 3.4 is defined in our language by using: i) an operation block with the inequality sign <=;ii) avariable block with the option CompartmentCargo and indexes sum and each;iii) a column block with the option Weight and index each. Since the constraints block only appears after the variables block the compiler knows the index values for both the column and variable used and thus can generate the correct constraints which in this case are also expressed in Figure 3.4. In LPBlocks, each constraint is defined by dragging a constraint block inside the constraints block (second and third blocks from the top in Figure 3.2.C) and then using the value blocks (blocks in Figure 3.2.D) and operation blocks (blocks following the constraint block in Figure 3.2.B) to express the constraints. In our language, operation blocks represent relations between blocks and are used to express several operations including arithmetic operations and inequalities. The value blocks can represent: • Columns; • Previously defined variables; 26
CHAPTER 4. IMPLEMENTATION AND ARCHITECTURE B A C D E Figure 4.4: Dynamic model generation in our application Error messages Another feature of our tool is the addition of dynamic error checking and messages, our goal with this feature is to help novice and more experienced users debug the constructed models as well as helping users learn our language and catch mistakes commonly associated with creating linear programming models and in using block-based languages. LPBlocks offers the following error messages: •Column with the given name already exists (Figure 4.5a): This error is given when the user attempts to create a variable with a name already used for an existing column. When outputting this message the variable generated by our model is colored red and the user can visualize more information about the error by hovering the mouse above the given variable. •Missing inequation in constraint (Figure 4.5b): This error is given when a user attempts to create a constraint without using an operation block with an inequation option. •More than one inequation in constraint (Figure 4.5c): This error is generated when the user attempts to create a constraint with two or more inequalities. This error is shown by highlighting the constraints associated with this attempt in red with a more descriptive message appearing when the user hovers the constraints. •Null values in expression (Figure 4.5d): This message is given when an expression contains Null values. 33
CHAPTER 4. IMPLEMENTATION AND ARCHITECTURE •Variable multiplication (Figure 4.5e): This error is generated when the user attempts to multiply two variables together. This message consists of a red highlight of the affected expressions with a more descriptive message consisting of the names of the variables that the user is attempting to multiply. •Empty fields (Figure 4.5f): This error is outputted when the user did not select the field in a selectable block. •Inequation in objective (Figure 4.5g): Given when the user attempts to use an inequation when creating the objective. •Each used in objective (Figure 4.5h): When the user attempts to use the option each in an objective. 4.1.2 Compilation process In this Subsection, we elaborate on the different aspects of the compilation process used to generate the linear programming mathematical formulations from our language. In Paragraph 4.1.2 we explain how the variables are generated from a block statement and the data coming from a spreadsheet. We then, in Paragraph 4.1.2, explain how we generate the constraints and the objective function. Generating variables To generate the variables into our internal representation when reading a variable block, our compilation process consists in reading the name of the given variable and depending on the blocks used we either: i) stop there for a single variable block, (ii)) read the variables index columns. The compiler then sets the variable name as a key to a list with the index columns used to create the variables as its value. The individual variables created with various iterations are computed when necessary. The process of computing the variables when given their name consists in retrieving the index columns array for the given variable, and calculating all possible permutations for the contents of the columns. An example of the outcome of this process can be visualized in Figure 3.3, in which the it was used a Matrix Variable block to define the variable and our compiler then iterates over both the columns passed as the input to generate the variables. Generating the constraints and objective The process of generating the constraints is not as forward as for generating the variables since creating the constraints in our language involves more blocks and complex operations that support polymorphism such as operation blocks with the Xoption. The first step to compute a constraint from our language to the mathematical formulation is to compute the value blocks, the output of the value blocks is dependent on the block used and its options and requires that information relative to some of the operations passes from the value blocks to the operation blocks, this information consists in indications for generating sums and iterations. To do so when accessing a particular value of a given column or variable we represent the value in our internal representation. 34
CHAPTER 4. IMPLEMENTATION AND ARCHITECTURE (a) Column with the given name already exists (b) Missing inequation in constraint (c) More than one inequation in constraint (d) Null values in expression (e) Variable multiplication (f) Empty fields (g) Inequation in objective (h) Each used in objective Figure 4.5: LPBlocks dynamic error messages If the user selects sum or each our internal representation contains indications that the user selected this option in the position of the index column for the value selected. We expand the each operation at the moment of parsing the inequation. This is due to the possibility that an iteration is applied to more than one variable or column and when this happens the compiler generates a single iteration. We expand the sum when parsing an operation or the objective since this operation can be used in more than one context that changes its meaning such as using it as part of a operation block with the option Xto create a sumproduct (as seen in Figure 3.4) of two columns or one column and one variable. Figure 4.6 showcases the compilation process of block that uses an each and sum operation. After compiling the value blocks to their respective location, sum, or iterations of a column or variable, we then compile the different operation blocks. The compilation of the operation blocks differs from the given operations: for the inequalities we first retrieve the different each indication and 35
CHAPTER 4. IMPLEMENTATION AND ARCHITECTURE Generate base expression from blocks Expand each expressions Expand sum expressions + Figure 4.6: Defining constraints - second example from Chapter 3 use them to generate the multiple constraints as seen in Algorithm 4.2 by first treating them as a set and generating constraints for all the permutations of the given columns. When generating the operation performed using the Xoption, the operation computed is dependent on the input given. Thus, if we are given either single values on both sides or a single value on one side and multiple values on the other, the single value is multiplied by each of the multiple values. When multiplying both values generated with the option sum asumproduct as seen in Algorithm 4.3 operation is generated. We opted for this option relative to doing a multiplication since we considered that it would be the most intuitive for our target audience. 36
CHAPTER 4. IMPLEMENTATION AND ARCHITECTURE For the +and -operation options we use the first input as the left side statement and the second as the right side statement. When a sum is not expanded as a sumproduct operation; it is replaced by a sum of the different values of the given index column as seen in Algorithm 4.1. The way we compile the objective is similar to the constraints, differentiating in not allowing for the use of each in value blocks and inequalities in the operation blocks. Algorithm 4.1 Expand sum expression 1: function expand_sum_expression(𝑒𝑥𝑝𝑟) 2: 𝑉𝑎𝑙𝑢𝑒𝑠𝑠𝑢𝑚 ←𝑓 𝑖𝑛𝑑𝑠 𝑐𝑜𝑙𝑢𝑚𝑛𝑠 𝑎𝑠𝑠𝑜𝑐𝑖𝑎𝑡𝑒𝑑 𝑤𝑖𝑡ℎ 𝑡ℎ𝑒 𝑠𝑢𝑚 𝑘𝑒𝑦𝑤𝑜𝑟𝑑𝑠 3: 𝑛𝑒𝑤𝑒𝑥𝑝𝑟 ←𝑒𝑥𝑝𝑟 4: for 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑣𝑎𝑙𝑢𝑒𝑒𝑎𝑐ℎ do 5: 𝑐𝑜𝑙𝑣𝑎𝑙𝑢𝑒 ←𝑔𝑒𝑡 𝑐𝑜𝑙𝑢𝑚𝑛 𝑑𝑎𝑡𝑎 𝑓 𝑜𝑟 𝑐𝑜𝑙𝑢𝑚𝑛 𝑣𝑎𝑙𝑢𝑒 6: 𝑠𝑢𝑚𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 ← [] 7: for 𝑐𝑒𝑙𝑙 𝑜𝑓 𝑐𝑜𝑙𝑣𝑎𝑙𝑢𝑒 do 8: 𝑠𝑢𝑚𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠.𝑎𝑑𝑑(𝑐𝑒𝑙𝑙) 9: end for 10: 𝑛𝑒𝑤𝑒𝑥𝑝𝑟 ←𝑛𝑒𝑤𝑒𝑥𝑝𝑟 .𝑟𝑒𝑝𝑙𝑎𝑐𝑒(”𝑠𝑢𝑚”+𝑣𝑎𝑙𝑢𝑒, 𝑠𝑢𝑚𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠.𝑗𝑜𝑖𝑛(”+”))) 11: end for return 𝑛𝑒𝑤𝑒𝑥𝑝𝑟 12: end function Algorithm 4.2 Expand each expression 1: function expand_each_expression(𝑒𝑥𝑝𝑟) 2: 𝑉𝑎𝑙𝑢𝑒𝑠𝑒𝑎𝑐ℎ ←𝑓 𝑖𝑛𝑑𝑠 𝑐𝑜𝑙𝑢𝑚𝑛𝑠 𝑎𝑠𝑠𝑜𝑐𝑖𝑎𝑡𝑒𝑑 𝑤𝑖𝑡ℎ 𝑡ℎ𝑒 𝑒𝑎𝑐ℎ 𝑘𝑒𝑦𝑤𝑜𝑟𝑑𝑠 3: 𝑛𝑒𝑤𝑒𝑥𝑝𝑟𝑠 ← [] 4: for 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑣𝑎𝑙𝑢𝑒𝑒𝑎𝑐ℎ do 5: 𝑐𝑜𝑙𝑣𝑎𝑙𝑢𝑒 ←𝑔𝑒𝑡 𝑐𝑜𝑙𝑢𝑚𝑛 𝑑𝑎𝑡𝑎 𝑓 𝑜𝑟 𝑐𝑜𝑙𝑢𝑚𝑛 𝑣𝑎𝑙𝑢𝑒 6: 𝑛𝑒𝑤𝑒𝑥𝑝𝑟𝑠.𝑎𝑑𝑑(𝑒𝑥𝑝𝑟.𝑟𝑒𝑝𝑙𝑎𝑐𝑒(”𝑒𝑎𝑐ℎ”+𝑣𝑎𝑙𝑢𝑒,𝑐𝑒𝑙𝑙)) 7: end for return 𝑛𝑒𝑤𝑒𝑥𝑝𝑟𝑠 8: end function Algorithm 4.3 Generate sumproduct 1: function generate_sumproduct(𝑒𝑥𝑝𝑟,) 2: 𝑉𝑎𝑙𝑢𝑒𝑠𝑒𝑎𝑐ℎ ←𝑓 𝑖𝑛𝑑𝑠 𝑐𝑜𝑙𝑢𝑚𝑛𝑠 𝑎𝑠𝑠𝑜𝑐𝑖𝑎𝑡𝑒𝑑 𝑤𝑖𝑡ℎ 𝑡ℎ𝑒 𝑒𝑎𝑐ℎ 𝑘𝑒𝑦𝑤𝑜𝑟𝑑𝑠 3: 𝑛𝑒𝑤𝑒𝑥𝑝𝑟𝑠 ← [] 4: for 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑣𝑎𝑙𝑢𝑒𝑒𝑎𝑐ℎ do 5: 𝑐𝑜𝑙𝑣𝑎𝑙𝑢𝑒 ←𝑔𝑒𝑡 𝑐𝑜𝑙𝑢𝑚𝑛 𝑑𝑎𝑡𝑎 𝑓 𝑜𝑟 𝑐𝑜𝑙𝑢𝑚𝑛 𝑣𝑎𝑙𝑢𝑒 6: 𝑛𝑒𝑤𝑒𝑥𝑝𝑟𝑠.𝑎𝑑𝑑(𝑒𝑥𝑝𝑟.𝑟𝑒𝑝𝑙𝑎𝑐𝑒(”𝑒𝑎𝑐ℎ”+𝑣𝑎𝑙𝑢𝑒,𝑐𝑒𝑙𝑙)) 7: end for return 𝑛𝑒𝑤𝑒𝑥𝑝𝑟𝑠 8: end function 37
CHAPTER 4. IMPLEMENTATION AND ARCHITECTURE 4.2 Spreadsheet reading service This service was created as a Rest API using Express.js5that accepts the upload of a given spreadsheet file and then reads it using the node-xlsx6library and sends back the contents of spreadsheet in JSON format as seen in Appendix A. To translate the data in the spreadsheet into our internal representation used to generate the constraints (this process can be seen in Figure 4.7) we load the data from the file into memory in the JSON format. Subsequently, we parse the JSON data into our internal representation. This process comprises the following steps: • Finding the index columns as seen in Algorithm 4.4: we do this by iterating over the list of columns names and selecting the first column and the first ones after an “Empty” column as seen in Algorithm 4.4 • Finding the indexes for each column as seen in Algorithm 4.5: to do this we iterate over the column names and set each column index column as the previous index column. • Finding the column data as seen in Algorithm 4.6: to do this task we first iterate over the column names and set the data of the column to its contents in the JSON readings. Listing 4.1: Input for the Solver API 1{ 2model: `Maximize 3obj: + 0.6 x1 + 0.5 x2 4Subject To 5cons1: + x1 <= 1 6cons2: + 3 x1 + x2 <= 2 7End` 8} Algorithm 4.6 Find column data 1: function find_column_data(𝑐𝑜𝑙𝑠) 2: 𝑐𝑜𝑙𝑢𝑚𝑛𝑑𝑎𝑡𝑎 ←𝑀𝑎𝑝 <𝑠𝑡𝑟𝑖𝑛𝑔,𝑠𝑡𝑟𝑖𝑛𝑔 >() 3: for 𝑐𝑜𝑙 𝑜𝑓 𝑐𝑜𝑙𝑠 do 4: 𝑐𝑜𝑙𝑢𝑚𝑛𝑑𝑎𝑡𝑎 ←𝑐𝑜𝑙𝑠[𝑐𝑜𝑙] 5: end for return 𝑐𝑜𝑙𝑢𝑚𝑛𝑖𝑛𝑑𝑒𝑥𝑒𝑠 6: end function 5https://expressjs.com/ 6https://www.npmjs.com/package/node-xlsx 38
CHAPTER 4. IMPLEMENTATION AND ARCHITECTURE Parsing Read spreadsheet in Json format Figure 4.7: Input data for the running example problem Algorithm 4.4 Find index columns 1: function find_indexes(𝑐𝑜𝑙𝑠) 2: 𝑖𝑛𝑑𝑒𝑥𝑐𝑜𝑙𝑠 ← [] 3: 𝑖𝑛𝑑𝑒𝑥 ←𝑇𝑟𝑢𝑒 4: for col of colnames do 5: if 𝑖𝑛𝑑𝑒𝑥 == 𝑇𝑟𝑢𝑒 then 6: 𝑖𝑛𝑑𝑒𝑥𝑐𝑜𝑙𝑠+=𝑐𝑜𝑙 7: 𝑖𝑛𝑑𝑒𝑥 ←𝐹𝑎𝑙𝑠𝑒 8: end if 9: if 𝑐𝑜𝑙 == ”𝐸𝑚𝑝𝑡𝑦”then 10: 𝑖𝑛𝑑𝑒𝑥 ←𝑇𝑟𝑢𝑒 11: end if 12: end for return 𝑖𝑛𝑑𝑒𝑥𝑐𝑜𝑙𝑠 13: end function 4.3 Optimization service The optimization service uses Express.js once again to create a Rest API. This API receives a JSON structure that includes the model in a format that the solver can run. The API then runs the model using the clp-wasm7library and sends the output back. This library is a port of the COIN-OR linear programming solver to WebAssembly. To use this service we also transform the formulation in our web application internal structure to the format seen in Listing 4.1. 7https://www.npmjs.com/package/clp-wasm 39
CHAPTER 4. IMPLEMENTATION AND ARCHITECTURE Algorithm 4.5 Find column indexes 1: function find_column_indexes(𝑐𝑜𝑙𝑠) 2: 𝑐𝑜𝑙𝑢𝑚𝑛𝑖𝑛𝑑𝑒𝑥𝑒𝑠 ←𝑀𝑎𝑝 <𝑠𝑡𝑟𝑖𝑛𝑔,𝑠𝑡𝑟𝑖𝑛𝑔 >() 3: 𝑖𝑛𝑑𝑒𝑥 ←𝑇𝑟𝑢𝑒 4: 𝑖𝑛𝑑𝑒𝑥𝑐𝑜𝑙𝑢𝑚𝑛 ←”” 5: for 𝑐𝑜𝑙 𝑜𝑓 𝑐𝑜𝑙𝑠 do 6: if 𝑖𝑛𝑑𝑒𝑥 == 𝑇𝑟𝑢𝑒 then 7: 𝑐𝑜𝑙𝑢𝑚𝑛𝑖𝑛𝑑𝑒𝑥𝑒𝑠 [𝑐𝑜𝑙]=𝑖𝑛𝑑𝑒𝑥 8: 𝑖𝑛𝑑𝑒𝑥 ←𝐹𝑎𝑙𝑠𝑒 9: end if 10: if 𝑐𝑜𝑙 == ”𝐸𝑚𝑝𝑡𝑦”then 11: 𝑖𝑛𝑑𝑒𝑥 ←𝑇𝑟𝑢𝑒 12: end if 13: end for return 𝑐𝑜𝑙𝑢𝑚𝑛𝑖𝑛𝑑𝑒𝑥𝑒𝑠 14: end function 40
Chapter 5 Language applicability In this chapter we intend to illustrate the applicability of our language to a broad set of examples. Doing so gives us some assurance that our language could be used as a replacement of other linear programming tools, still allowing users to solve their problems. We present a set of linear programming problems mostly taken from an MBA exam [4] and from an Operations Research textbook [5], and their modeling using LPBlocks. Our goal when choosing those problems was to have a set of problems representative of different linear programming workloads, difficulty levels and size, that would allow us to test and assess some possible shortcomings of LPBlocks. 5.1 Vegetable mixture This example shown in Figure 5.1 comes from the operations research textbook [5]. In this example, a manufacturer of freeze-dried vegetables aims at reducing production costs while adhering to various nutrition criteria and guidelines. We are given nutritional data for each of the vegetables as well as their cost per pound in the tabular data shown in Figure 5.1. We have a maximum percentage for certain vegetables and lower bounds for certain nutrients. Since our goal is to find the ratio of each vegetable that goes into the mixture, we created a column variable named Mixture that takes as its input the column Vegetable. For the constraints we start by creating constraints imposing limits of 40% (represented by the multiplication of 0.4) for beans and 32% for potatoes (represented by the multiplication of 0.32). The following three constraints define the lower bounds for the given nutrients. The objective is to minimize the cost per pound of the mixture. 41
CHAPTER 5. LANGUAGE APPLICABILITY LPBlocks Constraints Objective Generates Figure 5.1: Definition of the vegetable mixture problem using LPBlocks 5.2 Fruit canning plants In this example taken from an MBA exam [4] and shown in Figure 5.2 we are given information associated with different suppliers and fruit canning plants with the goal of maximizing its profits. The information includes shipping, labor and operating costs, buying prices and maximum production capacities. Despite not being in the spreadsheet, the problem definition states that the selling price for each tonne is $50. To generate the formulation we create a matrix variable with indexes Supplier and Plant. The constraints for this problem are straightforward and can be generically specified, this consisting of the upper bounds for the supply and capacity for each of the plants. The objective function is more complex since it needs to take into account the selling price and all the costs to represent the profit. 42
CHAPTER 5. LANGUAGE APPLICABILITY Generates Constraints LPBlocks Objective Figure 5.7: Cargo allocation problem in LPBlocks 49
C h a p t e r 6 Empirical evaluation We intend to assess if our language and tool can be used by people with little or even no linear programming experience. We want to understand how people react to its features and how users from different backgrounds interact with our language, tool and the concepts behind it. Thus, in this chapter we showcase an empirical study we designed and ran. 6.1 Design As said previously our aim is to observe the experience that different users have when using our tool to solve a plethora of problems and to collect their reactions and feedback. To achieve the desired outcome in this study we planned on doing hour-long sessions with each of the participants. During each of the sessions we plan on doing an initial introduction to linear programming and how our language can be used to model linear programming problems. We then introduce our tool and its features. After doing so we solve a demo exercise in front of the user, followed by a joint exercise where the user solves the problem with possibly extensive help from us and two individual exercises where the user solves the problem with our input only when necessary. Beyond solving the problems we created an individual follow-up questionnaire about their experience with our language and tool, prior experience and education, and other basic information such as age and gender. The questionnaire can be seen in Appendix Bfor questions related to the users background and Appending Cfor user feedback. Since the goal of this study is to get qualitative feedback from users and to see their difficulties and assess our solution viability with different types of users, we aim to have participants from different backgrounds and with different levels of experience with linear programming. Thus, we contacted via email and word of mouth possible participants with diverging academic and professional experiences. 50
CHAPTER 6. EMPIRICAL EVALUATION 6.2 Instrumentation During the session, we use several problems taken from the book and class notes referenced in Chapter 5and whose datasets in a spreadsheet format can be found at https://drive.google.com/drive/ folders/1SAle03APg4JZefFIleS3-1hYGJ3gURI. We use a web implementation of our tool that can be found at https://lpblocks.herokuapp.com. We used the same set of problems in all our sessions and those where: •Vegetable mixture - We used a portion of the problem seen in Section 5.1 containing only constraints retaining the maximum ratio of beans in the mixture and the absolute content of iron in the mixture. We used this problem as the tutorial problem. We decided to use this problem as the introductory problem since it showed a balance of complexity and relatability with the number of features of our tool shown during its resolution. •Fruit canning plants - We used this problem as presented in Section 5.2 to use as a joint exercise. This exercise is arguably more complex than the ones to be solved more independently by the user but allows the user to experience most of the features needed for solving the future exercises. •Pharmaceutical company - This problem is the first individual problem that the participants are asked to solve. This problem introduced in Section 5.4 is notably simpler than the previous problem and its simplicity lets the user focus on some of the core features of our tool and has the added benefit of decreasing the fear and intimidation for users less familiar with linear programming. •Computer manufacturer - This problem seen in Section 5.5 is the last of the individual problems. It is more complex than the first of the individual problems but allows the participants to put into practice various of our language features such as sumproducts between variables and columns and the use of the each option, requiring a more thorough thinking process for the interpretation and expression of the constraints in our language. 6.3 Execution To find participants for our study we contacted people in our circles as well and student groups of relevant subjects as said in Section 6.1. Our goal was to have a diverse group of participants and in our case that entailed increasing the efforts to acquire participants from non-computing backgrounds. Overall we were able to find 7 participants. Of this group 4 of the participants had a higher education degree in a computing field and were either currently Master or Ph.D. students. The other 3 had no computing degree, one of them worked in industrial engineering consulting and the other 2 work entailed doing web marketing, customer service, and logistics for e-commerce companies. All participants had at least a bachelor’s degree and all participants from the computing background were male and from the business background were female. 51
CHAPTER 6. EMPIRICAL EVALUATION The study was conducted with each participant at a time, in a think-allowed setting, using a videoconference software. The first step when starting the session was to ask participants to download the datasets for the session. Afterwards, we gave a briefing on linear programming and some of its uses and some of the difficulties associated with its use. After doing so we introduce our solution, explain that the results of the study will be anonymous, and reassure the participants that our goals are to collect qualitative feedback about our tool, that our tool has a learning curve and that we are not passing any judgment on the participants. After our introduction we start with the tutorial which is composed of an explanation and introduction to our language. This includes how the data is loaded from spreadsheets and its representation in the tool and our language blocks and their uses. We also give an explanation of some aspects of the compilation process and some of the caveats of our tools, we explain to the participant how to navigate our interface and finally do a live demonstration of one linear programming model creation using our tool. During this process, especially during the live demo, we encourage the participants to ask as many questions as they need. Our next step after the tutorial is to let the user solve one of our problems. To do so we ask participants to share their screen and then after an explanation of the problem and data we guide the user on how to solve the problem using our solution. During this step we allow the user to do some exploration and to solve as much of the problem as he can. Following the joint exercise, we start the first evaluation exercise. Both evaluation exercises are easier than the explanation exercise, the first one being easier than the second. After explaining the problem and data we allow the users to do as much as they can, only intervening when the user asks for help or it is necessary to avoid the user going on a wrong path. We then do the second problem similarly. After solving the problems we ask the user for any feedback and proceed to end the session and direct them to the form. 6.4 Data collection In this section we present the data collected from the forms: in Subsection 6.4.1 the portion relating to the participants background and in Subsection 6.4.3 the results relating to the feedback given by the users. In Subsection 6.4.2 we describe the individual session with each user. 6.4.1 Background data In this subsection, we present the background information about the participants of our study. The questions in the form relating to the subject are available in Appendix B. From the information in Table 6.1 ( whose questions can be seen in Appendix B), we were able to 52
CHAPTER 6. EMPIRICAL EVALUATION observe that our participants have an age distribution predominantly between 21-24 and 25-35. The distribution is split evenly between those two groups, beyond those we had one person over the age of 35 . In terms of gender we have 4 males and 3 females. In terms of academic background, we have 4 people with a computing background, 2 people with a business background, and 1 person with both a business and engineering background . In terms of degree, all our participants had post-secondary degrees, having slightly more participants with a Masters than with Bachelors and none with Ph.D.. When it comes to prior experience with linear programming we had 4 persons who took college classes and 3 persons with no experience at all. Participant Age Gender Degree Years of university Education field Linear programming experience Linear programming tools 125-35 Male Master 8 Computing Took college classes Programming tools 225-35 Male Master 8 Computing Took college classes Excel 325-35 Male Master 5 Computing Took college classes Programming tools, Other visual tools such as GAMS 421-24 Male Bachelor 5 Computing Took college classes Programming tools, Excel 5more than 35 Female Master 6 Engineering and Business None None 621-24 Female Master 5 Business None None 721-24 Female Bachelor 3 Business None Excel Table 6.1: Participants background gathered from the survey 6.4.2 Sessions In this subsection we describe the sessions with the different participants. Participant 1 During the tutorial the participant was able to understand the language and our goals, despite special emphasis had to be made when explaining the data and variables. The participant was proactive and was able to solve a considerable portion of the joint exercise. The participant also demonstrated interest in our tool and language. Relatively to the first individual problem, the participant tried to maximize the objective instead of minimizing. This error could have been made since the user might not have understood that our goal with this problem was not to increase the profit but to decrease production costs since the participant might have been more accustomed to maximization problems. Other than that the user did not need considerable amounts of help. When solving the second problem the user had some difficulties distinguishing between the option sum and each in the constraints and objectives. This user did demonstrate more difficulty in solving this problem than the previous one especially on how to express the costs in our language, but with some help the user was able to get to the correct solution. 53
CHAPTER 6. EMPIRICAL EVALUATION Overall the user had a positive reaction to our tool and was able to do a good portion of the exercises and we felt that the user understood the core of our language and tool and that with some more experience would be able to achieve mastery of our tool. Participant 2 During the language presentation the subject found himself interested in the language and its features, this being demonstrated by the subject asking several questions. When doing the first demonstration problem the user did have some difficulties on where to place the blocks. After the initial error, he was able to understand the logic behind the variable creation. Other problems subsequent during the demonstration were related to differences between each and sum, confusion between sum values from one column or variable, and using the operation block with the value +. This was solved. Despite some initial confusion, the participant was able to understand the language. During the first exercise, the major difficulty was representing the production in milligrams as the sumproduct of the vial quantity and the produced vials. The user was able to get the answer and understand the reasoning with some help. The main difficulty in the second problem was using two constraints, one for the labor and the another for the materials instead of using an each for both. The user ended up understanding the logic behind the model and did the rest of the model by himself. Overall we found that the user understood the core concepts of our language and with some training could become proficient in using it. Participant 3 The participant was attentive and asked several questions when watching the tutorial. When doing the first exercise the user was proactive and was able to solve a significant portion of it. Some difficulties involved the use of each and the use of columns and variables. When doing the second exercise the user was able to solve the problem on his own, the biggest problem being in using the correct block for addressing variables and discerning between column and variables blocks. When doing the third exercise the user experienced some confusion between the use of each and sum, but was able to solve the exercise. After our session, he manifested interest in our tool and gave some of his opinions related to our tool such as adding more solver options and exporting data to Excel files. Participant 4 The participant was interested in the language and tool and asked several questions. During the example exercise, the participant asked questions about block positioning and language features, particularly about the sumproduct operation. During the joint exercises, the user was proactive and found some initial difficulties when trying to represent the constraints and objectives in our language but ended up being able to continue with some help. The main problems were related to understanding how the data correlated with the desired goal of the constraints and objectives. This might be related to the user not using linear programming regularly. 54
CHAPTER 6. EMPIRICAL EVALUATION In the first exercise, there were some difficulties in creating the variables, particularly in creating 3 variables since the user tried to use 3 column variable blocks to create 3 variables, after visualizing the formulation generated by our tool we were able to understand the correct way to build the model. Understanding how to represent the constraints with the data took some tries but with some guidance and visualizing the output the user got to the correct answer. For the constraints, the user was able to create them correctly by visualizing the result, error messages and some trial and error. In the second exercise the participant’s main difficulty was in representing the variables. The rest of the model took some trial and error but with minor guidance and output visualization, the user was able to get to the solution. The user did do a manual sumproduct instead of using the sumproduct operation but that was a result of the trial and error process. With more practice, the user might gain some dexterity with the tool. 6.4.2.1 Participant 5 During the tutorial the participant was able to understand the purpose of our language and tool, although special emphasis had to be made when explaining the data and variables. Despite not being from a computing background this participant also had an engineering background and understood some of the concepts that our solution tackles, however, the user did demonstrate some skepticism to our language and its complexity for non-technical users. When doing the tutorial the user did not ask as many questions as the previous ones but did ask some. We tried to explain the concepts and how our tool could be used and the user seemed to understand the language’s purpose. The user did complement the interface and the features, but did feel intimidated by our tool and doubted her ability to solve problems such as the tutorial problem without our help. In response we reassured that after doing an exercise with us and gaining some experience the tool becomes easier and more intuitive. During the solving of the joint exercise we allow the user to try to understand the problem and ask any questions and give her input. Some of the difficulties the user had were in understanding the differences between the blocks for variable access and variable creation. We answered that and were able to convey their functions. Some of the operations such as sumproducts were not obvious. The user at the end of this exercise expressed some doubts about the virtue of our tool for users without any prior programming experience and admitted that despite her prior programming experience in one or two classes in college she still had difficulties understanding and working with our language. During the first individual problem the user was able to create the variables, understanding the mapping of our language to the mathematical formulation and how to write the expression was something that did not occur naturally but after the initial awkwardness and further explanation, the user was able to get over those hurdles. And once again understanding the differences between variables and columns and how the constraint in the natural language would be expressed in terms of data were only possible with some help and further explanations, but the user was able to get there on her own afterward. 55
CHAPTER 6. EMPIRICAL EVALUATION We were not able to do the last problem due to time constraints since we had planned on doing a one-hour session but by the time we finished solving the first individual problem the time was almost over and the user could not continue. 6.4.2.2 Participant 6 The user was interested during the presentation and during the demonstration exercise, where we gave special emphasis to explaining clearly the uses of linear programming and optimization. However, the participant did manifest some level of fear related to using our tool. Some of this previous hesitation had to do with the user not having a strong mathematical background. Despite the hesitation, the user did manifest some excitement with our tool and despite not doing any optimization in her line of work, she currently does use Excel for tasks related to marketing and business in general, including keeping track of stocks and inventory and interacting with logistics software. We did most of the joint exercise with this participant, but we saw that during the explanation the user was interested in the different features of our language. She was able to understand some of the solutions we created and the logic behind it. She also showed some appreciation for the interface with special relevance for the dynamic features, data visualization, and blocks. During the first individual problem the user showed some initial difficulty understanding what variable to create, but after explaining the purpose of the problem again and some trial and error with different blocks the user was able to get to the correct solution. For creating the constraint, understanding where to use the inequation was an initial problem, but was quickly corrected with some explanation. Creating the sumproduct was the harder part and both the blocks and which column and variable blocks and options to use require some extensive explanation. In the end, the user got to the solution and was able to understand the logic behind the use. For creating the objective the user still needed help but was able to get to the solution faster than for the constraint. When doing the last problem the user faced some difficulties when understanding the problem and creating the variable, this time the blocks were not an issue. For the constraints, there were still issues of blocks such as trying to use the wrong variable block to access a variable and a considerable amount of help was needed for the user to solve the problem, but, eventually, she did and there was some improvement compared with the first problem especially in understanding the blocks and how they were used. After solving this exercise the user expressed her liking for the interface and the blocks. She also affirmed liking the block-based language and made some comments about possible improvements such as improving the distinction between the constraint and variable value blocks. 6.4.2.3 Participant 7 When introducing the language the participant demonstrated interest in our solution, since she had work experience with Excel and found it to have some potential, however since the user did have little to no prior experience with linear programming the user felt intimidated by it at first. We made a special emphasis on 56
CHAPTER 6. EMPIRICAL EVALUATION explaining what linear programming entails and in explaining its components and how they relate to our language. The user during the presentation and tool showcase also expressed her liking for the interface and the language aesthetics and how the data was displayed. We did most of the joint exercise with this participant, but we saw that during the explanation the user was receptive to the different features of our language and was able to understand the solution we created and the logic behind it. During the first exercise, there was some difficulty in choosing which variable to use, but after re explaining the problem and how variables are created the user was able to get to the correct block, and using our visualization features the user was assured she made the correct choice. There were also some difficulties in representing the value in milligrams from the variable created and the value in milligrams for each vial, but the user was able to eventually understand how to do it, although with some help. The user was able to get the value in the spreadsheet to represent the total necessary medication in milligrams. The user was able to get the objective after some trial and help. During the second problem, the user was able to get the variable and part of the constraints. Once again the user needed help in doing the sumproduct and there was still some confusion in using the variable and column block and some help was warranted to achieve the correct solution. Also, some help was necessary to get to the objective but the user was able to solve portions of the problem. Despite the lack of previous experience with linear programming the user still appreciated the tool and was able to understand some concepts especially using our visualization and dynamic features. She also gave some advice consisting especially in improving the differentiation between variable and column blocks. When creating the constraints there was still some confusion on how columns and variables were used, but with some help she was able to get to the correct answer. 6.4.3 Participants feedback During the survey we asked for feedback about our tool from the users as well as some ideas and possible improvements that the users might believe would benefit our tool. To do so we added the questions in Appending Cto our survey, for which the results can be seen in Table 6.2. The details about the questions asked are in Appendix C. 6.5 Analysis and conclusions In this section, we present some conclusions and critical analysis related to the data gathered from our survey and the sessions and their implication on our work and possible future paths, changes, and applications. According to the data gathered from our sessions and survey, we can separate our participants into two different groups, one being the users 1 to 4 or the users with a computing background and 5 to 7 or the users with a business background. By coincidence, the computing group was all male and the business 57
CHAPTER 6. EMPIRICAL EVALUATION Participant Other tools Positive aspects Negative aspects 1Better usability. Usability; Performance; 2This tool has a strong visual component. Although Excel is algorithmically “more complete” UX is nice. Drag and drop works well. Also nice shortcuts: delete, ctrl+c ctrl+v. Constraints and Objective ”sub-windows”are useful to understand if the inequations match the user’s reasoning. Took me a while to understand the difference between “light-blue” variable block and “light-blue” column block. Each and sum are also a little confusing at first (but the previously mentioned sub-windows help fixing mistakes). 3Easy to learn interface, good visual aid (in the formula section - we can compare what the blocks translate to in terms of mathematical equations) Easy to learn interface, good visual aid (in the formula section - we can compare what the blocks translate to in terms of mathematical equations). No installation needed is a plus. No option export to file. For bigger problems / harder to solve problems, the lack of alternative solvers could result in not being able to solve the problem. 4Is not drag and drop like this app. Simpler Is not intuitive to beginners 5Easy to use, to grasp and get together. Terms of the buttons. Depending on the client if he doesn’t have the right knowledge it will be difficult to think in a problem solving logic. 6Visualy atractive; Well organized; All the information is well explained when building the model. The operations ordering is confusing. 7Very intuitive, easy to use, visualy appelative and well organized. We can visualize the model being created The order of the operations is not very intuitive. Table 6.2: Participants feedback gathered from the survey group all female, the computing group had on average more years of higher education and probably due to their field of study had prior experience with linear programming. Age-wise the differences were not starling. From our sessions, we were able to gather that all the participants were interested in our tool and interface and across the board (although possibly due to selection bias) asked various questions. The questions were different according to the user background, being slightly more technical in nature from the computing group. We also found that users universally liked the interface and how the data was accessible. This 58
BIBLIOGRAPHY [23] D. Solow. Linear Programming: Second edition. Dover Publications, 2014. 65
Appendix A Example spreadsheet data in JSON format Listing A.1: Spreadsheet data in JSON format 1{ 2[ 3{ 4Vegetables: 'Beans', 5Iron: 0.5, 6Phosphorus: 10, 7Calcium: 200, 8Cost_per_pound: 0.2 9}, 10 { 11 Vegetables: 'Corn', 12 Iron: 0.5, 13 Phosphorus: 20, 14 Calcium: 280, 15 Cost_per_pound: 0.18 16 }, 17 { 18 Vegetables: 'Broccoli', 19 Iron: 1.2, 20 Phosphorus: 40, 21 Calcium: 800, 22 Cost_per_pound: 0.32 23 }, 24 { 25 Vegetables: 'Cabbage', 26 Iron: 0.3, 27 Phosphorus: 30, 66
APPENDIX A. EXAMPLE SPREADSHEET DATA IN JSON FORMAT 28 Calcium: 420, 29 Cost_per_pound: 0.28 30 }, 31 { 32 Vegetables: 'Potatoes', 33 Iron: 0.4, 34 Phosphorus: 50, 35 Calcium: 360, 36 Cost_per_pound: 0.16 37 } 38 ] 39 } 67
Appendix B LPBlocks study form participant background questions 1. (Age) How old are you - In this question we give the participant the option to select one of the following options: a) Less than 18 b) 18-20 c) 21-24 d) 25-35 e) More than 35 f) Rather not answer 2. (Gender) What is your gender identity - In this question we give the participant the option to choose one of the following options: a) Male b) Female c) Other d) Rather not answer 3. (Education degree) Highest degree - We allow the participant to choose form one of the following options: a) Bellow High School b) High School 68
APPENDIX B. LPBLOCKS STUDY FORM PARTICIPANT BACKGROUND QUESTIONS c) Bachelor d) Post-graduation e) Master f) PhD 4. (Years of university) Years of post-secondary education - We allow the participant to choose one of the following options: a) 0 b) 1 c) ... d) 9 e) 10+ 5. (Education field) Main fields of study - We allow the user to choose multiple of the following options: a) Computing ( Computer Science, Informatics Engineering, Information systems, Information Technology, etc…) b) Life Science( Biology, Chemistry, etc...) c) Engineering( Electrical Engineering, Mechanical Engineering, Civil Engineering, etc...) d) Business( Economics, Business, Marketing, etc...) e) Humanities( History, Languages, etc...) f) Mathematics( Mathematics, Statistics) g) Other: ( fill in option ) 6. (Linear programming experience) What’s your academic experience with linear programming and operations research - We allow the particpants to choose from multiple of the following options: a) None b) Took college classes c) Degree in related field( ex Industrial engineering or statistics) d) Professional experience e) Other: ( fill in otpion ) 7. (Linear programming tools) Experience with optimization tools programming and otherwise - We allow the participants to choose from mutiple of the following options: 69
APPENDIX B. LPBLOCKS STUDY FORM PARTICIPANT BACKGROUND QUESTIONS a) Programming tools b) Excel c) Other visual tools such as GAMS d) Other: ( fill in option ) 70
Appendix C LPBlocks study form user feedback 1. (Other tools) If you used any of the tools above how do those compare to ours - This is a write in question. 2. (Positive aspects) What were in your opinion the positive aspects of our tool - This is a write in question. 3. (Negative aspects) What where in your opinion the negative aspects of our tool - This is a write in question. 71