As discussed in the class you project has the following description: 1. Download the data from the encode website. Only use DNase-seq data. Search for DNase and there will be thousands of experiments. On the search result page, on the left side there is a filter- choose the following parameters: Assay type ->DNase-seq, Biosample -> Homo sapiens, Organ-> blood, brain, bodily fluid (any one), Cell -> choose with the highest number of experiments associated with it. Analysis -> GRCh38. Read length (nt) ->101 OR 151 (choose any one). That’s enough filter. If you have to, you can change the cell/organ to find out a read length that has a higher number of experiments associated with it. Download at least 10 different files bed narrowPeak file type from 10 different experiments. 2. Convert the narrowPeak file into a nucleotide (ATGCs) file, using the bedtools. Let’s say these files are atgc_file just an example. 3. Extract all the nucleotides from this file and store the data into a different file containing only the nucleotide sequences and nothing else. So the file will contain many many rows of nucleotides each of them having different lengths. 4. The length of each sequence in the above file is of variable length. Come up with a number that optimally crops the sequences in such a manner that all the sequences are of the same length. If you have to discard sequences that are smaller than the number that you come up with, discard them. And trim the sequence which is longer than the number that you come up with. 5. Now you should have a file containing N_1 number of sequences each having length of X. For example 500 sequences, each of length 120. This is the positive file, Or the file containing all the accessible regions in the DNA. 6. Now we need a negative file Or a file containing all the regions that do not contain accessible regions. 7. To create this file use the narrowpeak file and subtract the distance of two consecutive accessible regions. That is to find the middle region between two accessible regions. 8. Go through the same process as described above and finally you are going to have a file containing N_1 number of sequences each having length of X. This 9. This file contains all the negative values or the sequences (ATGC) that do not represent accessible regions in the DNA. 10.Now you have two files, each having a different number (row) of DNA sequences but all having the same sequence length. 11. Now repeat this for the 10 different narrowPeak files from 10 different experiments. If you have any questions, happy to discuss during class, since this will help other students too. Most of the time I have to repeat the same solution to each individual which is not optimum. So I encourage you to ask those questions during the class time, I am more than happy to explain.
Please read the instructions carefully. Program-1 [25 points] Use the alexnet program and modify it to the conditions given below. Use the database MNIST already present in the pytorch. Instead of FashionMNIST it will be MNIST. Number of Classes in this dataset is 10. MNIST is a dataset to identify numbers, so the number of classes is 10. Make the batch size 16 and epoch should be 1 or 2. Layer1: 1. Input will be 1 channel i.e grayscale images 2. Apply 96 kernels, of kernel size 11, stride of 4 and padding of 0 3. Apply activation function ReLU Layer2: 1. Apply 96 kernels, kernel size 1 2. Apply activation function ReLU Layer3: 1. Apply 96 kernel, kernel size 1 2. Apply activation function ReLU 3. Do a maxpool2d, kernel size of 3 and stride2 4. Dropout of 0.5 Layer4: 1. Apply 256 kernel (hint the input to this conv2d layer is still 96) of size 11, stride 4 and padding 2 2. Apply activation function ReLU Layer5: 1. Apply 256 kernels, kernel size of 1 2. Apply activation function ReLU Layer5: 1. Apply 256 kernels, kernel size of 1 2. Apply activation function ReLU 3. Maxpool2d, kernel size of 3 and stride of 2. 4. Dropout of 0.5 Layer6: 1. Apply 384 kernels of size 3, stride of 1 and padding of 1 2. Apply activation function ReLU Layer7: 1. Apply 384 kernels of size 1 2. Apply activation function ReLU Layer 8: 1. Apply 384 kernels of size 1 2. Apply activation function ReLU 3. Dropout of 0.5 Layer 9 1. Apply 10 kernel (hint the input to this layer is 384) of kernel size 3, stride of 1 and padding of 1 2. Apply activation function ReLU Layer 10: 1. Apply 10 kernels of kernel size 1 2. Apply activation function ReLU Layer 11: 1. Apply 10 kernels of kernel size 1 2. Apply activation function ReLU 3. Finally apply nn.AdaptiveAvgPool2d((1, 1)) to the final output. There is no fully connected layer in this network; it is in the alexnet code that I have given. Modify the alexnet code appropriately. Program-2: [25 points] Use the database MNIST already present in the pytorch. Instead of FashionMNIST it will be MNIST. Number of Classes in this dataset is 10. MNIST is a dataset to identify numbers, so the number of classes is 10. Make the batch size 16 and epoch should be 1 or 2. Use the program you created for program-1 and layers-1 to layer-8 will be the same. Delete the layers-9 to 11. Instead plug in a fully connected (fc) layer (i.e. nn.Linear()). Remember now you are using the fc layer so please go back and understand the fc layer of alexnet. You have to flatten the data. Look carefully at the transform function, it is transforming the images into 224×224 images. MNIST data are usually 28×28. The transformation is scaling the data. So the input data will be 224×224 and grayscale (i.e. one input channel) The conditions are: A. In case of alexnet the input was 5*5*256, in this case the input will be X * Y * 384. Look at the output channel size of the last layer (i.e. previous to this layer). Calculate X and Y yourself. Remember the input image is of size 224×224 in the layer-1 because of transformation. Take help from the alexnet code and slide-8 of “introduction to Neural Network-II”. Important: In pytorch for output size determination they use the floor function. Layer-9: 1. Input channel to fc (or nn.Linear) will be X * Y * 384 and output will be 4096 2. Apply activation function ReLU 3. Dropout of 0.5 Layer-10: 1. Input channel to fc (or nn.Linear) will be 4096 and output will be 4096 2. Apply activation function ReLU 3. Dropout of 0.5 Layer-11:(actually this is not a layer but anyways) 1. Input channel to fc (or nn.Linear) will be 4096 and output will be Classes (number of classes) BONUS QUESTION: [15 Points] If you are able to draw the diagram of the network given in either program-1 or program-2 in the manner shown in slide number 8 of “introduction to Neural Network-II” slide deck. Upload the image into github. ZIP THE NOTEBOOK FILES AND SUBMIT IT TO MOODLE TOO FOR RECORD IF YOU HAVE ANY QUESTION ASK ME AFTER THE CLASS OR DURING THE CLASS, I AM HAPPY TO EXPLAIN.
CS 590 – Compu6ng in Healthcare Assignment 3 Responses1. Shallow neural networks are simple and typically contain only a single hidden layer between input and output, but deep neural networks can contain many more hidden layers that perform different transforma6ons and opera6ons on the data before reaching the output layer. 2. In neural networks, training occurs as a series of steps. First is the process of forward propaga2on, where data is fed into the input layer, through a series of hidden layers, where weights, biases, and ac6va6ons are applied. Upon reaching the output layer, the predic6on is made and forward propaga6on has completed. Then, the process of back propaga2on occurs where a loss func6on is used to determine how erroneous the predic6on was. The gradient of the loss func6on is calculated with regard to the weights and biases of the network. Some kind of op6miza6on algorithm like gradient descent, stochas6c gradient descent, or Adam is used to update the pervious values of the weights and biases so the network can “learn” from its errors. This process of the forward propaga6on followed by back propaga6on will iterate un6l an acceptable end state is reached. 3. Ac6va6on func6ons are used to introduce some non-linearity to the output of the neurons to bePer represent curves of real data as well as controlling which data actually gets sent through the network. 4. Some common hyperparameters include learning rate, epoch, batch size, ac6va6on func6on, loss func6on, regulariza6on func6ons/techniques. 5. OverfiVng is when the model is too complex and fits too closely to the (usually training) data, meaning that it will not work well on new data and will have high variance (very nonlinear). UnderfiVng is the opposite, where the model is too biased toward a simple paPern cannot effec6vely represent nonlinear rela6onships within the data. 6. OverfiVng is o[en mi6gated through techniques like regulariza6on and dropout, to help ensure that the model does not fit too closely to the training data. 7. The vanishing gradient problem is a scenario where the loss gradients get very small, almost to zero, during backpropaga6on. This happens o[en in networks with many layers, rapidly shrinking the shape of the data from input to output. This can be mi6gated through using ac6va6on func6ons like ReLU to restrict which informa6on passes through the network. The exploding gradient problem is the opposite scenario, where the loss gradients get very large, and the model becomes very unstable. Techniques like gradient clipping to clamp the values of gradients help mi6gate this unstable growth behavior. 8. Batch normaliza6on is a technique which helps improve the efficiency of the training process of neural networks. This opera6on is applied to individual layers of the network. Each mini-batch is normalized, then scaled and shi[ed according to learned scaling and shi[ing parameters. This allows for efficient learning with higher learning rates, lower internal covariate shi[, mi6ga6on of exploding and vanishing gradient problems, and reduced need for other regulariza6on techniques. 9. A Convolu6onal Neural Networks consists of a series of different types of layers, each type performing a certain role. The convolu6onal layer is the namesake of this type of neural network, which performs the convolu2on opera6on, which slides some number of kernels (filters) over the input data, crea6ng a feature map. It u6lizes parameters like kernel size, stride, and padding. The pooling layer is another type of layer in a CNN which is used to effec6vely compress the input data into a smaller representa6on (output data). This makes computa6ons more efficient and some6mes removes unwanted noise. These are o[en placed between consecu6ve convolu6on layers. The fully-connected layer is another type of layer which will typically occur near the end of the Network. These work on a flaPened version of the previous data, and are used to effec6vely make the higher-level predic6ons that we want the network to perform. 11. Convolu6onal neural networks can generally perform image processing tasks more efficiently than tradi6onal image processing techniques because they require less pre-processing and are automa6cally able to learn hierarchical feature representa6ons and can operate largely unsupervised by humans. 12. Different techniques can be used to effec6vely ini6alize values in a network. O[en, some sort of randomized distribu6on is a bePer star6ng point than just star6ng everything at zero. However, the proper ini6aliza6on technique depends heavily on the task at hand and the types of opera6ons the network is performing. 13. Some popular CNN architectures include AlexNet, VGG, and ResNet. Each of these model architectures were designed for different tasks and involve different combina6ons of convolu6on, pooling, and fully-connected layers. 14. Batch size is the number of training examples which are used in calcula6ng the loss func6on gradient before propaga6ng the informa6on back and upda6ng the weights of the model. In theory, larger batch sizes will give a more accurate es6mate of the loss func6on gradient, they will o[en realis6cally perform worse in generaliza6on to new data compared to smaller batch sizes. 15. When choosing the op6mal batch size, various things must be considered like capability of the hardware, learning stability, and model generaliza6on. Hyperparameter tuning techniques like grid search or Bayesian op6miza6on are o[en used to determine this ideal batch size. 16. Some common use cases for CNNs aside from image classifica6on are natural language processing, speech recogni6on, and 6me series analysis. We used it in class for DNA accessibility classifica6on. 17. Some techniques o[en used in hyperparameter tuning are grid search, random search, Bayesian op6miza6on, or simulated annealing. Similar to tuning of hyperparameters themselves, choosing the ideal op6miza6on techniques depends on various factors like hardware capability, necessary opera6ons, and scale of data. 18. Early stopping involves the use of a valida6on set during training, which is used to mi6gate overfiVng in the model based on some desired heuris6c(s) for which a stopping point is usually defined. 19. Data transforma6on is the processing of taking some input data and conver6ng into a format which is more easily usable for analysis. This can involve removing unnecessary features associated with the data, enumera6ng features that can be enumerated, aggrega6ng data into summary measures, and much more. This transforma6on is o[en necessary for effec6ve performance in a neural network model. 20. Some common transforma6on techniques include normaliza6on, scaling, encoding, rota6ng, discre6za6on, enumera6on, aggrega6on, imputa6on, and much more. 21. Effec6ve data transforma6on can help to op6mize the data representa6on into a state which is more meaningful in regard to rela6onships between features, efficiency in training, and far higher quality for solving par6cular tasks. Poor transforma6on can easily do the opposite, adding unnecessary noise or removing poten6ally useful features. 24. DNase-seq is an experimental DNA accessibility assessment technique with u6lizes the DNase I enzyme to selec6vely cleave DNA where it is not protected by nucleosomes or other proteins (meaning it is an open, accessible chroma6n region). ATAC-seq is another technique, but it uses a hyperac6ve Tn5 transposase to essen6ally tag open regions of the chroma6n which will highlight these accessible regions compared to the protected, inaccessible regions. 25. A BED file is a tab-separated-value (TSV) file with a single sequence entry per line. Each entry will contain columns for the name of the chromosome, the start posi6on of the chromosome, and the end posi6on of the chromosome, as well as various other op6onal fields. 26. To create the nega6ve (inaccessible region) BED file, we simply take the range between the end of the original accessible region and the start of the next accessible region for the same chromosome. We must validate that the values follow the proper bed format rules (no invalid ranges), and then we have generated a valid inaccessible region for our new BED file. 27. Bedtools is used to compare our regions against a reference genome and subs6tute the regions indicated in our bedfiles with the actual sequence of nucleo6des which exist in that range within the genome. This is crucial so we can learn the paPern of the data with our model. 28. Nucleo6des are the basic building blocks of DNA. DNA consists of four different types of nucleo6des (Adenine, Thymine, Guanine, Cytosine). There are 23 chromosome base pairs in the human genome. 30. The coding regions of DNA contain the instruc6ons for protein synthesis, which is used to describe how proteins and cells are to be synthesized, which is the basis for growth and development in organisms. 32. Data must be converted to a tensor for use in pytorch because the pytorch library is designed to effec6ve handle parallelized computa6ons, typically leveraging the power of the GPU’s many simple, focused cores to perform computa6ons. The tensor data structure allows for computa6on to be vectorized, and thus parallelized for great efficiency compared to standard sequen6al computa6on. These kinds of calcula6ons are incredibly common in deep learning. 33. If we ploPed our model’s loss with respect to the epoch, we would ideally no6ce a decreasing trendline (nega6ve slope). This would indicate that our model is performing bePer (less loss, bePer accuracy) as we run consecu6ve training itera6ons. 34. In deep learning, a valida6on set is useful for many kinds of tuning and op6miza6ons that we want to perform with our model. First and foremost, the valida6on set is useful for hyperparameter tuning. By checking performance of different hyperparameter values on a test data set and comparing the results to a valida6on set, the hyperparameter values can be tweaked according to this performance discrepancy to achieve more desirable results from the model.
Problem-1: 15 Points General description: Create a repository in github and make it public. You have to upload two files in this repository for this problem. One will be a bash script file which is going to install software packages and another will be a yml/yaml file that is going to instantiate your python environment. Bash Script file: Write a single bash script that at first updates the system and then install the following packages 1) htop 2) screen 3) miniconda. Yml file: Once you downloaded your required packages for jupyter server and functionalities, export the environment to a file called requirements.yml. After the export, push this file in your github repo. This file will automate your python environment creation process. How to go about this is given in one of the files in Moodle. Upload this yaml/yml file to the github repo. Problem-2: 10 Points General description: Create a bash script that copies all the files inside of a folder to another folder. The source and destination should be given as an input by the user to the script. Name the script appropriately and push it in the same repo where you pushed the problem-1 files. For example: ./my_copy_script.sh /users/manasdas/data1 /users/manasdas/output/results **************************************************END********************************************* The objective of doing this is that in the future the software and packages will grow. I do not want you to do things one by one every time, so this is where scripts come in, to automate the installation and configuration of the system. So learning this handy tool is going to save lots of your time and you will look professional instead of copy pasting code every time one by one. SUBMIT THE THREE FILES TO MOODLE TOO IF YOU HAVE ANY QUESTION ASK ME AFTER THE CLASS OR DURING THE CLASS, I AM HAPPY TO EXPLAIN.
Your database consists of the following tables: Your command-line interface should include the following functionalities. 1. The user can view the contents of each table. Show the name of each table and display the tuples of the table(s) that the user selects. (The user can select more than one tables to view.) 3. The user can search the database by specifying one or more input attributes from {AUTHOR, TITLE, YEAR, TYPE} and specify one or more output attributes from both tables. In addition, the user can specify a field on which the search result should be sorted. Your search should consider pattern matching for input strings. 4. Your program should exit only when the user chooses to. When your program starts, prompt the user for his/her Oracle username and password. Please do not hard-code your own login information in the code. After the program connects to the database successfully, prompt the user for the location of paper.sql script file when you create and insert data into the database from the script file. After the database is ready for search, print a menu like below and prompt the user to choose an option from the menu. If the user enters an option that is not valid, a message stating the option is invalid should be displayed and the menu is displayed again. 1. View table contents 2. Search by PUBLICATIONID 3. Search by one or more attributes 4. Exit When the user chooses one of the options listed below: 2. prompt the user for PUBLICATIONID 3. prompt the user for input fields, output fields, and a sorted field like below: Input fields: AUTHOR: TITLE: YEAR: TYPE: Output fields: PUBLICATIONID (Yes/No): AUTHOR (Yes/No): TITLE (Yes/No): YEAR (Yes/No): TYPE (Yes/No): SUMMARY (Yes/No): Sorted by: 4. Exit the program The output should be either in tabular form (with or without lines) or each field is separated by commas. Print out an error message when no (valid) inputs are specified and prompt for inputs again. Print out a message when no results are found and go back to the main menu. After an option is executed, your program should go back to the main menu. Extra credit: (10 Points) Create a GUI interface or a web application and give a demo to the GTA. Your interface should be user friendly and be able to achieve the same functionalities specified for command-line interface above. The deliverable: Submit your source file(s) and the script of running each option from the menu. Tips: The file Student.java includes Java commands for loading the necessary driver and connecting to Oracle database (Make changes to username and password). It will display the following information after it compiles and runs successfully: jdbc:oracle:thin:@artemis.vsnet.gmu.edu:1521/vse18c.vsnet.gmu.edu Connected. Database Product Name: Oracle Database Product Version: Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production Version 18.6.0.0.0 Database Driver Name: Oracle JDBC driver Database Driver Version: 18.3.0.0.0 Resources: 1. Quick start with JDBC https://www.oracle.com/database/technologies/develop-java-apps-using-jdbc.html 2. JDBC Tutorial https://docs.oracle.com/javase/tutorial/jdbc/basics/index.html 3. Oracle JDBC FAQ https://www.oracle.com/database/technologies/faq-jdbc.html 4. Execute SQL script using JDBC https://www.tutorialspoint.com/how-to-run-sql-script-using-jdbc https://github.com/mybatis/mybatis-3/releases/tag/mybatis-3.5.7
Learning Outcomes In this assignment, you will get practice with: • Creating classes and objects of those classes • Overloading constructors • Implementing equals(), toString(), getters, and other methods • Working with arrays • Using loops and conditionalsIntroduction Most of us are probably familiar with the beloved family game ‘Scrabble’. In Scrabble, players collect seven random tiles, each consisting of a letter A through Z (for the sake of simplicity, let us that assume the ‘blank’ tile does not exist in this version of the game). Players then use these tiles to create words that consist of one or more of the letters they’ve randomly selected. When a word is created using one or more of the seven selected tiles, the value of each of the tiles is summed, and that score is added to the player’s cumulative score. The individual value of each tile is presented below.Given the letters of seven randomized Scrabble tiles, you must determine the set of scores that a player could possibly obtain by placing these tiles. We will be assuming three traits that differ slightly from the traditional game of Scrabble: 1. There is an unlimited amount of every letter within the scrabble bag, thus it is reasonable to assume (though incredibly unlikely) that you could obtain something like [‘A’, ‘A’, ‘A’, ‘A’, ‘A’, ‘A’, ‘A’]. 2. You will be placing these tiles during the first turn on the board. Thus, you do not need to worry about combining your word with any pre-existing letters that might have already been placed on the Scrabble board. 3. Assume that there exist no word or letter bonuses. We will simply be basing the score off the tile values. As an example, assume that your seven randomized tiles read: {‘A’, ‘C’, ‘A’, ‘A’, ‘B’, ‘A’, ‘H’} The output should be 1) a list of length n of words that can be created using these letters, and 2) a list of length n containing the scores (integers) for each of the words of length 1 ≤ m ≤ 7 that can be created using these letters (like ‘AA’, or ‘AAH’, which are both words within the Collins Scrabble Word dictionary, surprisingly). So two of the scores that will be in your score set for the above tile set are 2 (A (1) + A (1) = 2), and 6 (A (1) + A (1) + H (4) = 6).Provided Files The following is a list of files provided to you for this assignment. Do NOT alter these files. – CollinsScrabbleWords2019.txt – TestGame.java Classes to Implement For this assignment, you must implement two java classes: Tile and Scrabble. Follow the guidelines for each one below.Tile.java This class represents a single Scrabble tile that will be used in the game. The class must have the following private variables: • value (char) The class must have the following public methods: • public Tile() [constructor] o Initialize value to ‘ ’ • public Tile(char) [constructor] o Initialize value to the given argument • public void pickup() o Generate a random character between A and Z (inclusive) and set the value to that letter. o Feel free to use ‘java.util.random’ for this method • public char getValue() o Returns the tile valueScrabble.java This class represents the Scrabble game in which there are seven randomly selected tiles, and scoring is performed for each possible word (this will be the tougher class to implement). The class must have the following private variables: • tiles (Tile[ ]) The class must have the following public methods: • public Scrabble() [constructor] o Initialize the Tile array and ‘pickup’ for random values • public Scrabble(Tile [ ]) [constructor] o Initialize the tile array with the given argument • public String getLetters() o Return a string that is all of the tile characters (for example, “ABFEODL”) • public ArrayList getWords() o Create an ArrayList of Strings with n elements. Each element should represent a word that can be created using the current tiles. o The algorithm for this method should reference the provided file CollinsScrabbleWords2019.txt o ** do NOT put this file somewhere on your local machine and hardcode the local directory. This will likely cause your tests to fail on GradeScope. Also, do not put it within a folder in the relative path. • public int[ ] getScores() o Create an int array with n elements. Each element in this list should represent each individual score for each word that can be created using the current tiles. This should be returned in ascending order. • public Boolean equals(Scrabble) o Compare the given Scrabble object from the argument with the ‘this’ object to see if they are equal (do they have the same tiles?).Marking Notes Functional Specifications • Does the program behave according to specifications? • Does it produce the correct output and pass all tests? • Are the classes implemented properly? • Does the program produce compilation or run-time errors on Gradescope? • Does the program fail to follow the instructions (i.e, changing variable types, etc)Non-Functional Specifications – Are the variables and methods given appropriate, meaningful names? Avoid things like ‘temp’, ‘myvar’, and ‘goodForNothingVariable’. – Is the code clean and readable with proper indenting and white-space? – Is the code consistent regarding formatting and naming conventions? – Submission errors (i.e, missing files, too many files, etc.) will receive a penalty of 5% – Including a “package” line at the top of a file will receive a penalty of 5%** Remember you must do all the work on your own. Do not copy or even look at the work of another student. All submitted code will be run through similaritydetection software.Assignments must be submitted to Gradescope, not on OWL. If you are new to this platform, see these instructions on submitting on Gradescope.Rules • Please only submit the files specified below. • Do not upload the .class files! Penalties will be applied for this. • Forgetting to submit is not a valid excuse for submitting late.Files to Submit • Tile.java • Scrabble.javaGrading CriteriaFunctional Specifications [1] Tile.java [6] Scrabble.java [10] Passing TestsNon-Functional Specifications [1] Meaningful variable names, private instance variables [1] Code readability and indentation [1] Code comments
Programming Assignment 2 – Graph Traversal Algorithms1. OverviewImagine you are given a dataset that represents a social network, where individuals are nodes in the graph, and their connections or friendships are represented as edges in an edge list. Your task is to analyze this social network to extract valuable insights. The dataset is in the form of an edge list. A visualization of the graph is shown below to help you.Input: An edge list file where each line represents a friendship connection between two individuals, e.g., “N_0, N_1.”Output: A report with a table such as the one below that documents the length of the shortest path between two individuals (or vertices) in this graph and the time taken to find the path between the two nodes. You must explore all pairs indicated in the table and complete the table below for each of the following algorithms. You should not include an entry if there are no paths between the two nodes. Use the graph above to identify if the nodes have paths connecting them.Node 1 Node 2 BFS DFS Distance Time (ms) Distance Time (ms) N_0 N_1 N_0 N_2 N_0 N_3 N_0 N_4 N_0 N_5 N_0 N_6 N_0 N_7 N_0 N_8 N_0 N_9 N_0 N_10 N_0 N_11 N_0 N_12 N_0 N_13 N_0 N_14 N_0 N_15 N_0 N_16 N_0 N_17 N_0 N_18 N_0 N_19 N_0 N_20 N_0 N_21 N_0 N_22 N_0 N_23 N_0 N_24You must explore the following algorithms. Breadth First Search (BFS) and Depth-First Search (DFS). For each of the node pairs in the table, you must run BFS/DFS with the start node as Node 1 and terminate the algorithm when Node 2 is reached. For example, to find the distance between N_0 and N_1, the start node is N_0. The algorithm terminates when N_1 is visited or “explored” by the algorithm. The distance is the total number of nodes visited by the algorithm before reaching the target vertex.Your report should also have a brief description of the data structure that you will use to represent the graph and a short justification.The goal of this assignment is to analyze how long it takes for BFS and DFS to reach nodes at different depths. Based on your experiments above, briefly answer the following questions with an example: 1. Suppose you want to find a path between nodes at a shallow depth to your start node. Would you use BFS or DFS? 2. Suppose that the end node is at a very large depth from the start node. Would you use BFS or DFS?
1. Overview To empirically evaluate 4 sorting algorithms and verify their theoretical upper bound. The sorting algorithms we will evaluate are: merge sort, quick sort, insertion sort, and selection sort. A starter code with helper functions and implementations of 2 algorithms (selection sort and merge sort) has been provided. Your task is to implement the remaining two sorting algorithms (quick sort and insertion sort) and perform the following empirical analyses. You will run a specific algorithm on three different types of arrays – sorted, random, or constant array of a given size n. The provided starter code will generate the input arrays for your analysis. The starter code will take as input three command line arguments in the following order: 1. Type of input array. You have three choices: ‘r’, ‘c’, and ‘s’ that correspond to random, constant and sorted arrays, respectively. If invalid values are given, it will default to a random input array. 2. Size of the array to generate and analyze. It must be a positive number greater than zero. It will default to 10 if an invalid value is provided. 3. Sorting algorithm to use. You have four choices: ‘m’, ‘i’, ‘s’, and ‘q’ that correspond to merge sort, insertion sort, selection sort, and quick sort, respectively. If an invalid value is given, it will default to quick sort. If an incorrect number of arguments are given or if an integer is not provided for the second command line argument, it will default to running quick sort on a random input array of size 10. For stable computation of timing, the starter code will run each algorithm three times and provides the median of the three runs. For accurate timing, ensure that there are no other processes running on the machine while you conduct your analysis. The output timing will be in nanoseconds. 2. Deliverables: There are two deliverables for this programming project: (i) the completed code with the two sorting algorithms completed in the functions marked with “TODO”, and (ii) a report with your analysis clearly marked with two sections – “Results” and “Analysis.” More details about what is expected to be presented in each section are provided below. 2.1 Results Run each of the four sorting algorithms on constant, sorted, and random arrays that are powers of 10. For each of the twelve cases, you should record the following: • Nmin: the smallest power of 10 array size that takes 20 milliseconds or more per run to sort. • Nmax: the largest power of 10 array size that takes 10 minutes or less per run to sort (30 mins for all 3 runs), or the largest input size you can successfully sort if no input took more than 30 minutes total. • Tmin: the time to sort an array of size Nmin. • Tmax: the time to sort an array of size Nmax. You should report your results in a table. Your table should have 12 rows and 5 columns. Each row must have a label with 2 letters, where the first corresponds to the algorithm (Merge, Quick, Insertion, or Selection) and the second corresponds to the array type (Sorted, Random, or Constant). For example, SS corresponds to Selection sort run on a Sorted array. An example table is shown below.2.2 Analysis In this section, you will estimate the complexity of the four algorithms by comparing the ratio between Tmin and Tmax to ratios representing the complexity of the algorithm. Specically, you should compute f(Nmax) = f(Nmin) for f1(n) = n, f2(n) = n ln(n), and f3(n) = n2. You should round to the nearest integer when computing these ratios. Finally, you should label each experiment according to the ratio Tmax=Tmin most resembles. For example, if you get Nmin= 10 and Nmax = 100, your ratios would be: • f1(Nmax)/f1(Nmin) = 100/10 • f2(Nmax)/f2(Nmin) = (100*ln(100))/ (10*ln(10)) • f3(Nmax)/f3(Nmin) = 1002/102 You should then label the algorithm based on which of these three ratios Tmax = Tmin is closest to. As part of your report, you should create a table that includes the computed ratios as well as the behavior of the algorithm (Linear, n lg n, or Quadratic), across all 12 experiments. An example is given below:Your report should contain a summary of (1) how your results compare to the theoretical analysis for all four algorithms, and (2) why your results make sense or are surprising. You should spend more time explaining your results when they are unusual or unexpected.
Programming Assignment 2 – Graph Traversal Algorithms 1. Overview Imagine you are given a dataset that represents a social network, where individuals are nodes in the graph, and their connections or friendships are represented as edges in an edge list. Your task is to analyze this social network to extract valuable insights. The dataset is in the form of an edge list. A visualization of the graph is shown below to help you.Input: An edge list file where each line represents a friendship connection between two individuals, e.g., “N_0, N_1.” Output: A report with a table such as the one below that documents the length of the shortest path between two individuals (or vertices) in this graph and the time taken to find the path between the two nodes. You must explore all pairs indicated in the table and complete the table below for each of the following algorithms. You should not include an entry if there are no paths between the two nodes. Use the graph above to identify if the nodes have paths connecting them. Node 1 Node 2 BFS DFS Distance Time (ms) Distance Time (ms) N_0 N_1 N_0 N_2 N_0 N_3 N_0 N_4 N_0 N_5 N_0 N_6 N_0 N_7 N_0 N_8 N_0 N_9 N_0 N_10 N_0 N_11 N_0 N_12 N_0 N_13 N_0 N_14 N_0 N_15 N_0 N_16 N_0 N_17 N_0 N_18 N_0 N_19 N_0 N_20 N_0 N_21 N_0 N_22 N_0 N_23 N_0 N_24 You must explore the following algorithms. Breadth First Search (BFS) and Depth-First Search (DFS). For each of the node pairs in the table, you must run BFS/DFS with the start node as Node 1 and terminate the algorithm when Node 2 is reached. For example, to find the distance between N_0 and N_1, the start node is N_0. The algorithm terminates when N_1 is visited or “explored” by the algorithm. The distance is the total number of nodes visited by the algorithm before reaching the target vertex. Your report should also have a brief description of the data structure that you will use to represent the graph and a short justification. The goal of this assignment is to analyze how long it takes for BFS and DFS to reach nodes at different depths. Based on your experiments above, briefly answer the following questions with an example: 1. Suppose you want to find a path between nodes at a shallow depth to your start node. Would you use BFS or DFS? 2. Suppose that the end node is at a very large depth from the start node. Would you use BFS or DFS?
In this lab you will be implementing a MIPS program that utilizes recursion. Recursion is the process a procedure goes through when one of the steps of the procedure involves invoking the procedure itself. It is one of the most important and frequent methods used in Computer Science. Now that you have a taste of protocol calls in MIPS, we will test it further by asking you to write a recursive MIPS program that prints all binary patterns of length N. Coding Problem In this assignment, you will write a MIPS program that read an integer range from 1 to 16, generate all binary patterns of length N, and output them line by line. In particular, the step-by-step procedure is: 1. Prompt the user to enter a number between 1 and 16 (inclusive), which will be the number of bits a single result string will have. 2. Write a recursive function to generate all strings that meet the condition. 3. Output all your strings. The smaller the number which the string represents in binary, the earlier it should be printed. 4. Terminate the program. 5. Since it is a fairly short lab (around 60 lines without blank lines and comments), the I/O is not given. Assignment Instructions Please download the provided lab7.asm file from the github repo and complete the MIPS code in the two TODO sections: PART 1 in which you will complete the body of the main procedure. PART 2 in which you will complete the body of the recursive procedure. Example I/O Enter the number of bits (N): 3 000 001 010 011 100 101 110 111 Program Specifications The name of your program file must be lab7.asm. Exception / Error handling is not required. That is, assume only valid values are entered by the user. The input and output must be the same as the examples provided above, in terms of: spelling, spacing, cases, etc. Assignment Submission and Grading Rubric Assignment submissions will be made through GradeScope. 1. Submit modifications using the commit Github Desktop instructions. 2. Update remote (origin) repository using the push Github Desktop instructions. 3. Go to the COMP 311 course in GradeScope and click on the assignment called Lab 07. 5. You should see a list of your public repositories. Select the one named lab-07-yourname and submit it. 6. Your assignment should be autograded within a few seconds and you will receive feedback.
Background Information Now that you have gotten used to looping and arrays in MIPS, we will test your mastery further by asking you to work with strings! As you surely learned through your experience in C, strings are more complicated to sort than numbers. To aid you in this task, you will write your first procedures in MIPS, which will help you compare and swap your strings. Coding Problem In this assignment, you will write a MIPS program that loads strings into an array, sorts them in alphabetical order (in terms of ASCII character code), and output your sorted array of strings, line by line. In particular, the step-by-step procedure is: 1. Prompt the user to enter a number between 1 and 20 (inclusive), which will be the size of the array in question. 2. Read in the string that should be stored at every index of the array. 4. Prompt the user to enter the value of the string that they would like to search for within the array. 5. Implement a bubble sort that will order the strings in the array in alphabetical order. 6. You will need to write two procedures to accommodate this functionality. The specifics of these two procedures are outlined in the Required Procedures section below. 7. Output your sorted array of strings in alphabetical order. 8. Terminate the program. Required Procedures lab_swap_strings Arguments: $a0 = starting address of strA, $a1 = starting address of strB. This procedure will be used in Step 4 during your sort. This procedures switches the contents of two elements of your array. For example, if the string starting at $a0 = “hello” and the string starting at $a1 = “goodbye”, then lab_swap_strings($a0, $a1) will result in the string starting at address $a0 = “goodbye” and the string starting at address $a1 = “hello”. To accomplish this, you should swap each character between both strings. Note: ensure the swapped strings are null terminated correctly after the swap. lab_compare_strings Arguments: $a0 = starting address of strA, $a1 = starting address of strB. Return value: $v0 should contain either -1, 0, or 1 depending on the result of the string comparison. This function will be used for sorting in Step 4. The return value stored in $v0 should be -1, 0, or 1 depending on whether strA < strB, strA == strB, or strA > strB. Return -1 if strA < strB. Return 0 if strA == strB. Return 1 if strA > strB. In order to determine which string is “greater” than another alphabetically, utilize their ASCII character to integer encoding values. Compare character-by-character starting with the beginning of each string, and continue until you find a differing character or reach the end of one of the strings See the following examples: apple < apply. The first four characters are the same, and then e < y since the ASCII integer value for character e is 101 and the ASCII integer value for character y is 121. Return -1. apple > applY. The first four characters are the same, and then e > Y since the ASCII integer value for character e is 101 and the ASCII integer value for character Y is 89. Return 1. apple == apple. Each character is the same. Return 0. app < apple. The first three characters are the same, and then there are no more characters left to compare. This technically means that the fourth character of “app†is the null terminator, which has an ASCII integer value of 0 while the ASCII integer value for character l is 108. 0 < 108, so we return -1. Assignment Instructions Please download the provided lab6.asm le from the repo. For ease of use, all portions of the code relating to I/O have already been provided for you and you should not modify them. Additionally, numerous comments are provided which will guide you through the assignment. Please complete the MIPS code in the three TODO sections: PART 1 in which you will complete the body of the main procedure. PART 2 in which you will complete the body of the string swap procedure. PART 3 in which you will complete the body of the string compare procedure. Example I/O The following consist of two different input and output case examples that demonstrate the expected output for the above program. Example 1 Enter array size [between 1 and 20]: 5 A[0] = Super Mario Galaxy A[1] = Wii Sports A[2] = Animal Crossing City Folk A[3] = Legend of Zelda Skyward Sword A[4] = Donkey Kong Country Returns The sorted array of strings is… A[0] = Animal Crossing City Folk A[1] = Donkey Kong Country Returns A[2] = Legend of Zelda Skyward Sword A[3] = Super Mario Galaxy A[4] = Wii Sports Example 2 Enter array size [between 1 and 20]: 10 A[0] = iPhone A[1] = Nintendo Switch A[2] = Apple Pencil A[3] = Fitbit A[4] = MacBook A[5] = iPad A[6] = Samsung Galaxy A[7] = Thinkpad A[8] = amazon Alexa A[9] = Surface Pro The sorted array of strings is… A[0] = Apple Pencil A[1] = Fitbit A[2] = Macbook A[3] = Nintendo Switch A[4] = Samsung Galaxy A[5] = Surface Pro A[6] = Thinkpad A[7] = amazon Alexa A[8] = iPad A[9] = iPhone Note that lowercase characters have greater ASCII values than uppercase characters. Program Specications Exception / Error handling is not required. That is, assume only valid values are entered by the user. Valid values consist of strings of 100 characters or less. Important: The input and output must be the same as the examples provided above, in terms of: spelling, spacing, cases, etc. We will use an auto-grader that compares your input-output solution with the correct one. You will lose points if they are formatted differently. Assignment Submission and Grading Rubric Assignment submissions will be made through GradeScope. 1. Submit modifications using the commit Github Desktop instructions. 2. Update remote (origin) repository using the push Github Desktop instructions. 3. Go to the COMP 311 course in GradeScope and click on the assignment called Lab 06. 5. You should see a list of your public repositories. Select the one named lab-06-yourname and submit it. 6. Your assignment should be autograded within a few seconds and you will receive feedback.
Computing Environment and MARS Lab Objectives To gain experience with comparison, branch, and jump instructions in MIPS Coding Problem In this assignment, you will write a MIPS program that loads integers into an array, sorts them in numerical order from lowest to highest, and searches the sorted array to see whether a particular integer is contained within the array. In particular, the step-by-step procedure is: 1. Prompt the user to enter a number between 1 and 20 (inclusive), which will be the size of the array in question. 2. Read in the integer that should be stored at every index of the array. 4. Prompt the user to enter the value of a number that they would like to search for within the array. 5. Perform a bubble sort that will order the integers in the array from lowest to highest value. 6. Perform a binary search on your sorted array and indicate whether the search value is present. If it is present, indicate the index of the array at which it was found. 7. Terminate the program. You will be responsible for coding steps 4 and 5. Please download the provided lab5.asm file from the github repo. You will see that numerous comments are provided which will guide you through the assignment. Most I/O has been provided for you, however you will be required to print the output of your binary search at the end of the program. Make sure to look at examples from earlier portions of code to demonstrate how to do this. Please complete the MIPS code in the two TODO sections indicated in the lab5.asm file: PART 1 in which you will sort the array using the bubble sort algorithm. PART 2 in which you will search the array for the specified value using the binary search algorithm. Important: The input and output must be the same as the examples provided below, in terms of: spelling, spacing, cases, etc. We will use an auto-grader that compares your input-output solution with the correct one. You will lose points if they are formatted differently. If you have any clarifying questions, please ask your cohort leader Example I/O The following consist of three different input and output case examples that demonstrate the expected output for the above program. Example 1: Enter array size [between 1 and 20]: 5 A[0] = -1 A[1] = 2 A[2] = 5 A[3] = -9 A[4] = 8 Enter search value: 4 4 not in sorted A Example 2: Enter array size [between 1 and 20]: 4 A[0] = 1 A[1] = 2 A[2] = 10 A[3] = -1 Enter search value: 2 Sorted A[2] = 2 Example 3: Enter array size [between 1 and 20]: 4 A[0] = 0 A[1] = 0 A[2] = -1 A[3] = -2 Enter search value: 0 Sorted A[2] = 0 Submit your assignment Assignment submissions will be made through GradeScope. X3PR75. If you’re unable to self enroll, please contact your cohort leader and we’ll manually add you. 1. Submit modifications using the commit Github Desktop instructions. 2. Update remote (origin) repository using the push Github Desktop instructions. 3. Go to the COMP 311 course in GradeScope and click on the assignment called Lab 05. 5. You should see a list of your public repositories. Select the one named lab-05-yourname and submit it. 6. Your assignment should be autograded within a few seconds and you will receive feedback.
Next: Configure MARS Enable pseudo-instructions: go to Settings then select Permit extended (pseudo) instructions and formats Enable compact memory address layout: go to Settings->Memory Configuration and select Compact, Data at Address 0. then press the Apply and Close button. Finally: Run the example assembly programs In this repo you will see the following two example assembly files: Sum.asm and SumArray.asm The bottom pane has two tabs: MARS Messages shows errors or warnings during assembly Run I/O is the input/output. Run each of the two programs. Make sure you understand every single line of code. Here is what to expect for each: Sum.asm: Single-step through the program, and observe that the result (i.e., sum of numbers 0..4) will be in register $8 at the end of execution. SumArray.asm: Single-step through it, and observe that the result (sum of 7, 8, 9, 10, and 8) will be in the sum variable (at data address 0x0 in the memory). More Info There are several library routines provided by MARS that an assembly program can use. These are called system calls, or syscall. These services include support for printing integers and strings (similar to the printf() function in C), reading integers and strings from the keyboard (similar to scanf() in C), memory allocation (similar to malloc() in C), exiting from a program (similar to return from main() in C), etc. An assembly program accesses those services using the syscall command. There is only one syscall command for all these services, but which service is requested is determined by the values provided in certain registers. The value in register $v0 determines which service is requested, and often parameters are passed to the service using registers $a0, $a1, $a2 and $a3. If a value needs to be returned to the program (e.g., reading an integer from the keyboard), it is typically returned in register $v0. For a full listing of system calls available in MARS, please refer to http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html. We will mostly be using system calls numbered 1 to 17. For example, to exit a program, you would use syscall with 10 in $v0: addi $v0, $0, 10 # system call 10 for exit syscall # exit the program Part 1: Basic I/O and Arithmetic You are given a program in MIPS assembly language that computes the area of a rectangle given the width and the height (ex1.asm). The width and height are read from the standard input after prompting the user, and then the program computes the area and prints it on the standard output. Here’s an example scenario: Enter width (integer): 2 Enter height (integer): 4 Rectangle’s area is 8 Modify the program so that it also calculates and prints the perimeter (i.e., sum of all sides) of the rectangle. Thus, after modification, the example scenario would become: Enter width (integer): 2 Enter height (integer): 4 Rectangle’s area is 8 Its perimeter is 12 Part 2: Loops Create a new assembly file called “ex2.asm”. Copy your final ex1.asm file to ex2.asm. Modify the program in ex2.asm to make it work on multiple inputs. In particular, it should repeatedly ask for width and height values, and print the corresponding area and perimeter, until the user enters the value 0 for width. At that point, the program should terminate. Here’s an execution scenario: Enter width (integer): 2 Enter height (integer): 4 Rectangle’s area is 8 Its perimeter is 12 Enter width (integer): 5 Enter height (integer): 6 Rectangle’s area is 30 Its perimeter is 22 Enter width (integer): 0 Test your program in MARS, and once you are satisfied that it is working properly, commit your changes and submit to Gradescope to run the autograder. Submit your assignment Assignment submissions will be made through GradeScope. 1. Submit modifications using the commit Github Desktop instructions. 2. Update remote (origin) repository using the push Github Desktop instructions. 3. Go to the COMP 311 course in GradeScope and click on the assignment called Lab 04. 5. You should see a list of your public repositories. Select the one named lab-04-yourname and submit it. 6. Your assignment should be autograded within a few seconds and you will receive feedback.
That’s right: no k-maps in this lab :raised_hands: :partying_face:! In the next lab we’ll be able to put these concepts together, so don’t worry if they seem a little disjointed right now! Part 1: Constructing a 4-bit ALU To recap: An arithmetic logic unit (ALU) is a digital circuit used to perform arithmetic and logic operations. It represents the fundamental building block of the central processing unit (CPU) of a computer Most of the operations of a CPU are performed by one or more ALUs, which load data from input registers. A register is a small amount of memory that is a component of a CPU. In this lab we’ll be using 3 registers (A, B, and C). A and B will be the register that the ALU reads from, and C will be the register that the ALU writes to. Additionally, a set of control bits tells the ALU what operation to perform on the data, and the ALU stores the result in output register C. In this portion of the lab you’ll get experience working with several components such as register, an ALU, and a clock. As we learned in class timing is needed to perform ALU operations. For example, writing the values to registers A & B will take one clock cycle (the first rising edge), and then writing the output of the ALU operation to register C will take 1 clock cycle (the second rising edge). See the image below:Thus, when you construct your ALU you should observe a time delay from when the input is read from registers A and B, and the output is written to register C. The ALU time delay should be much less than the one clock cycle (or clock period). Ask yourself: why don’t we need a clock cycle (in our representation) to perform the operation that happens inside the ALU? To-Do: Your task is to succesfully implement a working ALU that can performing addition, subtraction, logical AND, and logical OR. The ALU should function based on the control table below: |Math | Sub | Function | |—|—-|—-| |1 |0 |Addition | |1 |1 |Subtraction | |0 |0 | Logical AND | |0 |1 | Logical OR | Let’s get started. If you open the ‘Lab03_ALU.dig’ file you will see a that all input/output components have been provided for you. Let’s go through them: In the top left you will see two components “CLK” and “Enable”. These two components are crucial and must be connected to each of the registers in the circuit (12 in total). They should be connected to “C” and “En” respectively on each register. The “Enable” bit is what allows data to be written to the register, e.g., if it is set to 1, then the next rising-edge clock event the register will store the data. The enable bit is the same as the “in” bit we discussed in class. The CLK component is our clock. To the right of these components you will see eight inputs (A0 – A3 and B0 – B3) which represent the four bits that go to register A and four bits that go to register B. Under them, you will see eight registers (four for A, and four for B). We could have simply used two 4-bit registers, but spliting it up in eight 1-bit registers simplifies the circuit creation on your end. The input component should be connected to the “D” input on the register, and “Q” is the output of the register. These eight “Q” outputs will be inputs to the ALU. On the left-hand side you will see two additional inputs “Math” and “Sub”. These are the control bits that will be used inside your ALU. Remember, the function of your ALU is determined by these two control bits, and the function table above. Hint: If you remember from class, these control bits are the input to multiplexers within the ALU that determine what result is passed to the output register. Lastly, at the bottom, you will see four registers, and four outputs (C0 – C3) that represent the output from the ALU. After you complete the part, go through this checklist to see if your ALU is up to spec: Does your ALU perform operations and write to the C register only when the enable bit is 1? If writing occurs when enable is 0, you’ve done something wrong. Does your ALU correctly perform binary addition, subtraction, logical AND, and logical OR with the input from the A and B registers? Example: If A is 0000, B is 1111, math is 0, sub is 1, and enable is 1, then on the first rising edge your ALU should read the inputs A and B, and on the next rising edge, your ALU should write “1111” to registers C0 – C3. This was a logical OR operation. When you change input values, does it take 2 clock cycles to change the output to the C register? Remember we need a full clock cycle to write information to registers A and B from inputs A and B, and then a full clock cycle to write to register C. Ask yourself: why don’t we need a clock cycle (in our representation) to perform the operation that happens inside the ALU? You can simulate rising and falling edges yourself by right-clicking the CLK component, and unchecking the “start real-time clock” button. Now when you simulate the circuit, when you press the CLK component that is a rising edge and when you press again that is a falling edge. Here’s what you should see when you simulate: First start the circuit Then turn on the enable bit and the control bits that you want selected Then set your input bits A0-A3 and B0-B3 to whatever you want them to be When you press the CLK component once (rising edge), you should see that the data from the input registers has traveled into your ALU (the wires will light up bright green) When you press the CLK component again (falling edge), nothing should happen When you press the CLK component again (rising edge), the output should have been written to the C register. Notice how the whole operation took 2 rising edges, or in other words, 2 clock cycles. Once you get this working hopefully it helps you understand how timing works within an ALU. You can then recheck the “start real-time clock” button on the CLK component, to automate the rising and falling edges. Once you think your ALU is working, commit your changes, and move on to the next part of the lab! Part 2: Constructing an Efficient 4-bit ALU Two clock cycles?? Horrific! Blasphemous! Not in today’s world of efficiency! :scream: :exploding_head: In this part of the lab you will edit your circuit from part 1 to run operations (reading from A & B registers, and writing to C register) within ONE clock cycle. To do this please make a new Digital file in the same directory as your previous file called ‘Lab03_ALU_Efficient.dig’ and copy your entire circuit from the previous part. You’ll need to make one small (and when I say small, I mean small. Don’t go changing your entire circuitry from the previous section) change to your previous circuit to support this efficiency. Hint: Notice how in the previous part, on step 5, we “do nothing” on the falling edge. How inefficient…. Notice how one small change can cut our operational time in half! Incredible! :astonished: Once you have your operations working correctly within 1 clock cycle, commit your changes and move on to the next part of the lab! Part 3: Constructing a Digital RAM Component Time to completely switch gears. In this part of the lab we are going to implement a a digital RAM component. What is RAM? Random access memory (RAM) is one of the most important components in determining your system’s performance. RAM gives applications a place to store and access data on a short-term basis. It stores the information your computer is actively using so that it can be accessed quickly. RAM is memory, and in our lab we will be implementing a circuit that allows you to both read from memory, and write to memory. In our case, our RAM chip will support 4 bits. What does this mean? Every piece of information that is stored in RAM is at a specific Memory Address. This address is what is used to read/write data to and from. For example, if I want to store the number “2” in memory, I need to tell my RAM chip where to store that “2”, this is the memory address. Conversely, if I wanted to read data from a specific memory address, I could tell the RAM chip to give me the data that is stored in a specific memory address. For a 4-bit RAM, we can have 16 unique binary combinations of 4 digits, and thus we can have 16 unique memory addresses. Open the file ‘Lab03_RAM.dig’, let’s go through it: In this circuit we have 3 main components: 1. A “Memory Address Register” or MAR. This is the leftmost register that you see in this circuit. The purpose of the MAR is to provide the memory address to the RAM chip for either a write instruction or a read instruction. The data that the MAR sends to the RAM chip determines where the RAM will read/write in memory. For instance if the MAR sends 0000 to the RAM chip, the RAM chip knows to either read or write to memory address 0000. 2. The RAM chip. This is the center chip between the two registers. This chip is what controls reading and writing to the 16 memory addresses. 3. The “Memory Data Register” or MDR. The MDR is only used when you want to lookup or read a value from memory. For instance if the MAR sends 0000 to the RAM chip, and you want to lookup the value stored in memory address 0000, then the RAM chip will send the data in memory address 0000 to the MDR. Notice how even though we are constructing a 4-bit RAM, there are only 2 registers, not 8 like in part 1 of this lab. This is because each register is set to accept 4 input bits, and output 4 bits as well. The RAM is also configured to accept and output 4 bits. You can see this by ctrl-clicking the components and seeing that the data bits are set to 4. We also have a slew of input components. Let’s go through them: 1. ADR: This is a 4-bit input (ctrl-click and see that the data bits are set to 4) that is responsible for specifying the memory address you want to read from or write to. When you simulate the circuit and click on this input you’ll actually be able to change the binary value of the 4 bits. 2. ADRRegEnable: This a 1-bit input that specifies whether the MAR is active. If 1, the MAR can be written to, if 0 it cannot 3. Write: This is a 1-bit input that specifies whether we want to write data to memory. If 1, we are writing to memory, if 0 we are not writing. 4. Lookup: This is a 1-bit input that specifies whether we want to read data from memory. If 1, we want to read from memory, if 0 we do not. 5. Data: This is a 4-bit input that determines what value will be written to memory. This component does not matter if write is set to 0. 6. DataRegEnable: This ia a 1-bit input that specifies whether the MDR is active. If 1, the MDR can be written to, if 0 it cannot. 7. CLK: This is our clock, remember that writing can only only on rising clock edges. Lastly we have the output component on the right side that will display the value of the MDR if we are reading from RAM. 1. The ADRRegEnable input should always be set to 1 (we should always have the option of writing to the memory address register) 2. When ‘Write’ is 1, the 4 bit input from ‘Data’ should be written to the memory address specified by ‘ADR’. You can check this during the simulation by clicking on the RAM component, which will show the 16 memory address’ and their respective data. Remember that reading/writing should only happen on rising clock edges, you can simulate this by doing what you did in part 1 with the clock input. 3. When ‘Lookup’ is 1, and DataRegEnable is 1, the output component should display the data value in memory at the memory address specified by ADR. Let’s walk through scenarios 1 & 2 to see if your circuit is working. Scenario 1 (Writing) 1. Start the simulation 2. The CLK should be pulsing 3. Click on ADR and set the value to 3, either by typing 3 in the textbox or checking the corresponding binary boxes at the bottom 4. Set ADRRegEnable to 1 5. Set Write to 1 6. Click on the Data component and set the value to 5, either by typing 5 in the textbox or checking the corresponding binary boxes at the bottom 7. Click on the RAM component, you should see that in address 0x3, the value is 5. 8. Stop the simulation Scenario 2 (Reading) 1. Repeat steps 1-8 from Scenario 1 above 2. Set Write to 0 3. Set Lookup to 1 4. Set DataRegEnable to 1 5. The output component should display 5 6. Stop the simulation Notice how there’s a slight delay when trying to display values, that’s how the timing works in a RAM chip, remember we can only write on rising clock edges If this is working congratulations! You’ve constructed a simple 4-bit RAM module! You now have the ability to store data in memory and access it using control bits that you specify. To ensure your RAM module is working correctly, input the following data at the corresponding addresses given this address/data table (the values are in hex, your input components use binary, you need to convert, ie: for address 0x0 the correspoding ADR input should be 0000): |Address | Data | |—|—-| |0x0 |0x3 | |0x1 |0x7 | |0x2 |0x6 | |0x3 |0xA | |0x4 |0xE | |0x5 |0x2 | |0x6 |0x1 | |0x7 |0x4 | |0x8 |0x6 | |0x9 |0xD | |0xA |0xB | |0xB |0x2 | |0xC |0xF | |0xD |0x4 | |0xE |0xE | |0xF |0x9 | Once you have input this data, click on the RAM chip to see that it was all stored correctly. To ensure you will pass the autograders tests, try to see the values in the output component by using the lookup input (make sure Write is 0)! You should be able to set ADR to each of the 16 addresses, and see the corresponding value in the output component (following the steps from Scenario 2). In the next lab we’ll actually be connecting our ALU and our RAM module to take the information that was processed by the ALU and store it in memory! Once you’ve finished this part of the lab save & commit your changes! When you finish everything save and commit all your changes! Submit your assignment Assignment submissions will be made through GradeScope. 1. Submit modifications using the commit Github Desktop instructions. 2. Update remote (origin) repository using the push Github Desktop instructions. 3. Go to the COMP 311 course in GradeScope and click on the assignment called Lab 03. 5. You should see a list of your public repositories. Select the one named lab-03-yourname and submit it. 6. Your assignment should be autograded within a few seconds and you will receive feedback.
Sequential logic circuits are the backbone of constructing finite-state machines, a topic you will cover in Comp 455. Here’s a blurb from Wikipedia that explains the usefullness of sequential logic circuits: Sequential logic is a type of logic circuit whose output depends not only on the present value of its input signals but on the sequence of past inputs, the input history as well. This is in contrast to combinational logic, whose output is a function of only the present input. That is, sequential logic has state (memory) while combinational logic does not. A great example of sequential logic is below: A familiar example of a device with sequential logic is a television set with “channel up” and “channel down” buttons. Pressing the “up” button gives the television an input telling it to switch to the next channel above the one it is currently receiving. If the television is on channel 5, pressing “up” switches it to receive channel 6. However, if the television is on channel 8, pressing “up” switches it to channel “9”. In order for the channel selection to operate correctly, the television must be aware of which channel it is currently receiving, which was determined by past channel selections. The television stores the current channel as part of its state. When a “channel up” or “channel down” input is given to it, the sequential logic of the channel selection circuitry calculates the new channel from the input and the current channel. Objective Our goal for this lab is to create a 3-bit counter. Essentially, we want to design a circuit that “counts” upwards, from 0 to 7. Electronic counters come in two types: Asynchronous and Synchronous. In this lab we will build a Synchronous counter. Synchronous counters use a common clock and logic between their components to encode the count sequence. In these types of counters, the flip-flops are clocked at the same time by a common clock pulse. Thus, all the flip-flops change state simultaneously (in parallel). The counter advances upward in sequence (0, 1, 2, 3, 4, 5, 6, 7). The counter advances to the next output state on the positive edge of the input clock. State Diagram The next step in designing our 3-bit circuit is to design a State Diagram. This is a diagram that is made from circles and arrows and describes visually the operation of our circuit. In mathematic terms, this diagram that describes the operation of our sequential circuit is a Finite State Machine. The state diagram of our circuit is shown to the right. Every circle represents a So, what does our “Machine†do exactly? It starts from the “000†state and waits until a 1 is read at the input. Then it goes to the “001†state. As our clock continues, the circuit goes to the third state, “010â€, and so on. Note that if the input to a state is 0, the machine stays in it’s current state. This gives us the functionality of advancing to the next output state on the positive edge of the input clock or “pausing” the clock and remaining in the current state. We will come back to analyzing this state diagram soon. T Flip-Flops There are indeed many ways to make a 3-bit counter. You can use D or JK flip-flops, but in this lab we will use a T flip-flop. You should have learned about D flip-flops in class, and hopefully this lab will expose you to a different type of flip-flop, the T flip-flop. There are many different types of flip-flops; however, they are all sensitive to clock edges, but they perform different actions in response to the input states. The “T†in “T flip-flop†stands for “toggle.†When you toggle a light switch, you are changing from one state (on or off) to the other state (off or on). This is equivalent to what happens when you provide a logic-high input to a T flip-flop: if the output is currently logic high, it changes to logic low; if it’s currently logic low, it changes to logic high. A logic-low input causes the T flip-flop to maintain its current output state. To-Do: Truth-Table Based on State Diagram For our 3-bit counter we’re going to need 3 T flip-flops! Each output of a T flip-flop will be one binary digit of our number (0-7). What we need is to create a truth table that displays the current state, output states, and values of T based on our state diagram. Using the state diagram previosuly displayed in the lab, fill in these values. Q represents the current state, Q* represents the next state, and Ti represents the input to the flip-flop. Fill out the file “state-diagram-truth-table.csv” with the completed table. Let’s give a little more information to make sure the concept is completely clear. C, B, A -> Represent the binary digits of the numbers we are counting. Ex. 001 -> 1, 010 -> 2, 100 -> 4, and so on. For 001, C -> 0, B -> 0, 1 -> A QC, QB, QA -> Represent the current state of our machine. Ex. 101 means that QC -> 1, QB -> 0, QC -> 1. If 101 is the current state of the machine, then what are the possible next states? 101 can either transition to 101 (stay the same) or to 110 (increase to 6). That means in our truth table we will have 2 rows where QC, QB, QA are 101 respectively. The QC QB QA* for one row will be 101 (stay the same; input = 0 ) and another row will be 110 (change states; input = 1). To-Do: (notice input 0 and input 1)* ie. |1 |0 |0 |1 |0 |0 |1 | These will be the first two rows of your truth table. Notice how the first row represents the output state when the machine does not change states, and the second row is moving to the next state. K-Maps To-Do: | | QA Input(Y) | |——-|—-| |QC QB| value of Ti | Implementation: Now that we have our three expressions representing what the input “T” should be for each of our T flip-flops, it’s time to wire it up in Digital. I’d recommend drawing the circuit on paper first Create a file called “Lab02.dig” to build your circuit. You can find the flip-flop you need under components -> Flip-Flops -> T-Flip-Flop. You’ll also need a clock for this assignment. Find the clock under components -> IO -> clock input. When you place your clock make sure to right-click (control-click on mac) and check the box labeled “start real time clock”. To-Do: Compelete the circuit needed to wire up the 3-bit counter. The “T” input is what you solved for in the k-map. “Q” is the output of that digit. Ignore Q-bar, its just the inverse of Q. Each output Q of the three T-Flip-Flops should be connected to an output component. Label each of your output components as QC, QB, and QA respectively. You should also label your input component “Y”. You must also label your clock component “CLK”. At this point, when you start the simulation you should see the output components start to turn on and off in a fashion that counts upwards (only when the input Y is set to 1, when input Y is set to 0, the clock should hold steady in it’s current state). Now the fun part: Create a file called “Lab02fun.dig”. Copy your circuit from “Lab02.dig” and paste it into this file. Also, copy your entire circuit from the previous Lab 1 (the seven segment display) and paste it into this document. Now instead of sending the Q outputs to an output component we’re going to send them to the inputs of the 7-segment display to watch our machine count! Step 1: Delete inputs B, C, and D in the Lab01 circuit Step 2: Remove the output components for QC QB and QA from the Lab02 circuit Step 3: Connect output QC to where your old input B was to the Lab01 circuit Step 4: Connect output QB to where your old input C was to the Lab01 circuit Step 5: Connect output QA to where your old input D was to the Lab01 circuit Now when you start the simulation you should be able to watch the 7-segment display also count up (Only when input y is set to 1. If y is set to 0 you should see the 7-segment display hold steady in it’s current state)! This is also a great way to ensure your circuits are correct. When you finish save and commit all your changes! Submit your assignment Assignment submissions will be made through GradeScope. 1. Submit modifications using the commit Github Desktop instructions. 2. Update remote (origin) repository using the push Github Desktop instructions. 3. Go to the COMP 311 course in GradeScope and click on the assignment called Lab 01. 5. You should see a list of your public repositories. Select the one named lab-02-yourname and submit it. 6. Your assignment should be autograded within a few seconds and you will receive feedback.
Seven-segment displays are widely used in digital clocks, electronic meters, basic calculators, and other electronic devices that display numerical information. If you’ve never seen a 7-segment display before, here’s one below:As you can see, there are 7 seperate LED’s that turn on & off depending on the number (or letter) that you want displayed. A 7-segment display has four Boolean inputs (A, B, C, D) and Seven Boolean outputs (Fa, Fb, Fc, Fd, Fe, Ff, Fg) that represent display segments. In general, four Boolean inputs are decoded to seven Boolean outputs that will be used to display 1 of 16 hexadecimal values (0, 1, 2, 3, 4, 5. 6, 7, 8, 9, A, b, c, d, E, F). To determine what value will be displayed on the 7-segment display you take the binary combination of the 4 input bits and convert to hexadecimal, and the hex-value is what should be displayed. For instance when the 4 input bits are 0000, this translates to hex-value 0, and 0 is what is displayed. For input bits 1111, this translates to hex-value “F”, and this is what is displayed. The image to the right shows the layout of the 7 LED’s: Additionally, the following truth table to the right is crucial to constructing the circuit for a 7-segment display: For example, when inputs A, B, C, and D are all off (0=off) then output segments Fa through Ff will be turned on (on=1) to display the hex value “0†We’ve updated the truth-table for you above. Similarly, the output segment Fa will be turned on for the following input combinations – I’ve also updated the truth-table for you. A,B,C,D=0 A,B,D=0 and C=1 A,B=0 and C,D=1 A,C=0 and B,D=1 A,D=0 and B,C=1 A=0 and B,C,D=1 A=1 and B,C,D=0 A,D=1 and B,C=0 A,C=1 and B,D=0 A,B,C=1 and D=0 A,B,C,D=1 Task 1 Using the given “truth-table.csv” file in the repo, fill in the rest of the truth table. Determine for each number or letter, which of the 7 LED’s will be on (1) or off (1). You will see that the the given row and column is also given in the excel document. When you finish the truth table, we reccomend commiting your changes and submitting to Gradescope to see if it is correct. If you have an incorrect truth table, your circuits in the next part will not be correct! Task 2 Now that we’ve constructed the truth table, it’s time to get ready to build the circuit! Before we start diagramming on Digital, we need to figure out how we’re going to wire the 7-segment display up. Step 1 Using the completed truth-table, find the sum of products (SOP) Boolean expression (not simplified) for output segments Fa – Fg Simplify the SOP Boolean expression for each of the output segements Fa – Fg using the Boolean identities. Alternatively, you can contruct Karnaugh maps based on the completed truth-table for each output segment Fa – Fg, and use the Karnaugh map to find the simplified SOP boolean expression At this stage you should have 7 boolean expression in SOP form that are as simplified as possible. if you don’t simplify the boolean expressions or put them in SOP form, you’re going to have a very tough time while constructing the circuit in Digital Step 2 Draw the combinational logic circuits for each of the SOP expressions you obtained in Step 1. This will be the basis for what we are going to input into Digital Step 3 Now comes the hard part, actually putting & combining these circuits in Digital. Note: This is going to be a complicated circuit We’ve provided a template file for the assignment, labeled “Lab01.dig” in the repository. Make sure to build & commit your changes in this file. We’ve provided you 4 inputs labeled A-D, these are the only inputs you will need for this assignment! Note: Each of your 7 circuits you drew in step 2 will use the same 4 inputs A-D Construct your circuits! You can select logic components from the “Components -> Logic” menu. You should only need AND, OR, and NOT components for this assignment. You can find the 7-segment LED display under “Components -> IO -> Displays -> Seven-Segment Display” Note: DO NOT use the Seven-Segment Hex Display Remember that each of your 7 circuits will connect to one of the LED’s on the Seven-Segment Display. I’ve provided the image on the right to display which circuits connect to which inputs on the display. The bottom right input on the display must connect to ground. You can find the ground element in “Components -> Wires -> Ground” IMPORTANT When you finish wiring up your circuits, you should have 7 OR gates in your design (7 SOP expressions -> 7 OR gates). Each of these OR gates should lead to one input on the 7-segment display as shown in step 3. Below is an example: In order for the autograder to work, you MUST add output (Components -> IO -> Output) components on the end of each OR gate and label the component (using right-click for windows and control-click for mac) with the input that it is going to, (Fa, Fb, Fc, Fd, Fe, Ff, Fg). Don’t touch your wires, just place the output component on the output of each OR gate, and then label it accordingly. You MUST label the output components as (Fa, Fb, Fc, Fd, Fe, Ff, Fg) exactly as written. Below is an example:Task 3: Submit your assignment Assignment submissions will be made through GradeScope. 1. Submit modifications using the commit Github Desktop instructions. 2. Update remote (origin) repository using the push Github Desktop instructions. 3. Go to the COMP 311 course in GradeScope and click on the assignment called Lab 01. 5. You should see a list of your public repositories. Select the one named lab-01-yourname and submit it. 6. Your assignment should be autograded within a few seconds and you will receive feedback.
The goal of this lab is to get comfortable with the basic conventions of circuit diagrams such as: power, ground, wires, mechanical switch, and light emitting diode (LED). At the end, you should be comfortable with: – Working with Github Desktop, – designing and testing simple circuits using the Digital software application, and – submitting your solution to Gradescope. 1. Github Desktop Throughout this semester, you will be responsible for managing (cloning & committing) to your Github repositories so they can be linked to Gradescope for assignment submission and grading. Instead of using git commands in a terminal, we strongly recommend you to use GitHub Desktop. The links below provide step-by-step intructions along with visual aids about how to use Github Deskop: * Install GitHub Desktop. * Authenticate to GitHub. * Clone a repository from GitHub to GitHub Desktop. * Commit your changes to the repository. * Push your changes to the repository. 2. Digital: Circuit design and simulation software Follow the instructions on the Digital GitHub page for downloading and running the software program (no installation required). In short, you simply download the .zip file, unzip it, and run the software. Note: A Java Runtime Environment (at least JRE 8) is required to run Digital. To start Digital on Windows simply double click the provided Digital.exe executable file. To start Digital on Mac and Linux open a terminal and then execute the provided Digital.sh shell script from the command-line. Within Digital, you can access a useful help document by clicking Help > Documentation. We recommend reading: – Section 1: How to navigate through the program and create simple circuits. – Secion 3.2: LED with two connections. – Sections 6.1 and 6.2: Ground and voltage supply or power. – Section 13.1: Mechanical on/off switch. 3. Circuit Design Using Digital, we’ll wire up a very simple circuit that uses power, ground, one or more switches, and one LED. In general, when the switch is closed the LED will turn on (color will be red) and when the switch is open the LED will be turned off (color will be black). Adding an LEDs a great way to visually test the output of your circuit. First, clone the Lab 0 repository using the clone Github Desktop instructions provided above. 3.a First circuit TODO: After cloning the Github repository for Lab 0, start Digital and open the file Lab00a.dig. You do not need to edit this circuit in any way, it serves simply as an example of what a completed circuit in Digital looks like. Use this file to familiarize yourself with the Digital software. For example, pressing the play button in the top right corner of the Digital software will allow you to simulate the circuit. Try flipping the switch and seeing how it affects the output of the LED. Inspect carefully how the LED is wired, notice which components represent power (logic 1) and which represent ground (logic 0). When you press the play button, certain wires will light up, these wires are the ones that are connected to power. Understanding and analyzing how this circuit works will be crucial to being able to complete the second part of this lab. 3.b Slight enhancement to first circuit This part is just a slight enhancement of the circuit in Section 3. We’ll modify our circuit to act as a kind of “mechanical AND gate,†where the LED will only turn on if two switches are both in the closed position. This is simply wiring two switches in series, not using any AND gates (or indeed any logic gates at all). The one complication in this part of the lab is that we want to wire the two switches in such a way that the LED will only turn on when both switches are in the closed position. This will require some small modification to the switch wiring: one switch will need to select between ground and the output of the previous switch. There is one important step you must take while constructing Digital circuits for this class. Every time you place a switch, you must right-click (control + click for Mac) the switch. This will open an options menu for the switch, where among other things, you can label the component. You will notice that all components are already labeled for you. For both switches that are placed in this circuit for you, go to the “advanced” options menu, and make sure you check the box labeled “Switch behaves like an input”. This will allow the autograder to work. If you don’t do this step, the autograder will not work! Remember, you must enable this option for every switch in your circuit, and this step must be done in all future Digital labs as well!TODO: Construct your design in Digital using Lab00b.dig file as a start. You should only need to add wires and delete wires, not add any additional components. Verify that your design works in Digital by using the play button to simulate the circuit. You should only see the LED light up when both switches are in the closed position. What to submit? After modifying the file Lab00b.dig in order to implement the functionality shown above, you should commit and push your changes to your Lab 0 Github Repo. 4. Submit your assignment Assignment submissions will be made through GradeScope. 1. Submit modifications using the commit Github Desktop instructions provided above. 2. Update remote (origin) repository using the push Github Desktop instructions provided above. 3. Go to the COMP 311 course in GradeScope and click on the assignment called Lab 00. 4. Click on the option to Submit Assignment and choose GitHub as the submission method. You will be prompted to sign in to your GitHub account to grant access to GradeScope. When this occurs, make sure to grant access to the Comp311-SP22 organization. 5. You should see a list of your public repositories. Select the one named lab-00-yourname and submit it. 6. Your assignment should be autograded within a few seconds and you will receive feedback.
Introduction In this assignment, you will use the model-view-controller design pattern together with the JavaFX UI library to design a complete, functioning GUI implementation of the single-player logic puzzle nonograms. If you’ve never heard of nonograms before, I highly suggest starting by checking out the nonograms Wikipedia page. After you do that, try solving a few nonogram puzzles yourself to make sure you’ve got the hang of it. The nonogram app that you will design will be very similar to the nonograms implementation on the website linked above. You are encouraged to be creative with regard to the visual design of your implementation. Feel free to theme your user interface, move the components around in different locations, add new features, or make other significant changes to the look and feel of your app. However, your implementation must have the following features at a bare minimum for full credit: 1. If the user left-clicks on a cell, that cell becomes shaded. But, if they right-click on a cell, that cell becomes eliminated—just like the reference implementation. There must be a visual difference between a shaded and an eliminated cell. A cell cannot be both shaded and eliminated. Cells must be clearly marked, so the user can tell which cell they are selecting. 2. If the user left-clicks on an already-shaded cell, that cell should return to a blank state. If the user right-clicks on an already-eliminated cell, that cell should return to a blank state. 3. After each move, your app must check to see if the user solved the puzzle. If so, the UI must visually update to let the user know that they completed the puzzle. The puzzle is “solved” if the shaded squares match the clues. Non-shaded squares do not need to be labeled “eliminated” in order to solve the puzzle. 4. The UI must include a clearly visible and labeled “reset” button that will clear all the cells in the board and let the user start over from a blank state. 5. The starter code contains a pre-coded library of 5 puzzles to solve. The UI must provide clearly visible and labeled buttons to go to the next puzzle, to go to the previous puzzle, and to jump to a random puzzle. The “previous” button should not cause an uncaught exception if the user accidentally presses it on the first puzzle. Similarly, the “next” button should not cause an uncaught exception if the user accidentally presses it on the last puzzle. 6. The library of puzzles is a List, which means the puzzles are indexed. Your app must clearly display the index of the active puzzle in the library and how many puzzles are in the library in total. The displayed index should start from one, not zero. In other words, the first puzzle in the List (at index 0) should be displayed as “puzzle 1 of 5” to the user. 7. Your app must support arbitrary-sized boards with different widths and heights. To demonstrate this functionality, the provided pre-coded library of puzzles includes puzzles of at least two different sizes. Starter code Once you’re familiar with nonograms, take a look at the starter code defined in the repository. Three packages have been created to help you organize your code according to the model-view-controller pattern. In these packages, a few starter interfaces and classes have been defined to help you structure your app. It is not strictly necessary to use all the provided starter interfaces. Most of them are just there to give your app some structure and help you plan your code. If you would rather come up with your own design, there are a few rules that your code must follow so that your code can be autograded correctly. First, you must provide a ModelImpl and CluesImpl class as specified below. Second, running the main() method of the provided Main class must launch your GUI (this is how the LAs will launch your app for manual grading). Other than these two requirements, you are free to safely ignore the rest of the provided interfaces. Running the application This assignment uses Maven as a build manager, and JavaFX as a GUI library. Since JavaFX is an external library, it has to be included in the build process in order for the application to successfully run. JavaFX has already been added as a Maven dependency to the POM file. To run the application with Maven in IntelliJ, follow these steps: 1. Click the vertical “Maven” expansion tab which is on the right side of the IntelliJ window. 2. Expand the “Plugins” folder. 3. Expand the “javafx” folder. 4. Double-click “javafx:run” to run the project. Important: This is exactly the same process that a learning assistant will use to launch your app when they manually grade it. Make sure your app can be launched using this process in your final submission to Gradescope. Main class The Main class represents the starting point of your application. When you use Maven to launch your app as described above, Maven will try to run the Main.main() method to launch your app. You are free to change the contents of the Main class as necessary, but keep in mind that the Main.main() method will always be the starting point of your application. PuzzleLibrary To make your life easier, the starter repository comes with a class called PuzzleLibrary. PuzzleLibrary exposes a class factory method, create(), which instantiates and returns a singleton List list of Clues objects (see below for details). You can use this to set up a puzzle library in your model. If you want, you can add more puzzles to the puzzle library. Model All code related to the application’s model should be placed in the model package. Clues Take a look at the Clues interface. Each Clues instance represents the clues for a single nonograms puzzle. In particular, a Clues instance should encapsulate the following concepts: 1. The height of the puzzle (i.e. the number of rows in the puzzle) 2. The width of the puzzle (i.e. the number of columns in the puzzle) 3. An array of integers for each row in the puzzle, representing the clues for that row 4. An array of integers for each column in the puzzle, representing the clues for that column Clues instances are intended to be immutable—that is, the fields of a Clues instance should not change after instantiation. CluesImpl You must create a class named CluesImpl in the model package which implements the Clues interface. This is required for your submission to be autograded. The CluesImpl class should expose a constructor with the following signature: java public CluesImpl(int[][] rowClues, int[][] colClues) { // Constructor code here } The rowClues parameter is a two-dimensional array containing the clues for each row of the puzzle (top-to-bottom), and the colClues parameter is a two-dimensional array containing the clues for the columns of the puzzle (left-to-right). Spaces can be represented by zeros in the clue arrays. For example, this puzzle is represented by the following instance: “`java int[][] rowClues = new int[][] { new int[] {0, 2}, new int[] {1, 2}, new int[] {0, 3}, new int[] {0, 3}, new int[] {1, 1}, }; int[][] colClues = new int[][] { new int[] {1, 1}, new int[] {0, 1}, new int[] {0, 3}, new int[] {0, 3}, new int[] {3, 1}, }; Clues example = new CluesImpl(rowClues, colClues); “` Board A Clues instance represents the clues for a puzzle, but doesn’t handle the state to track whether individual cells are “shaded” or “eliminated”. The Board interface is intended to track the array of states for each cell in a puzzle. In other words, a nonogram puzzle is a combination of a Clues object, representing the clues for the puzzle, and a Board object, representing the states of the puzzle’s cells. Instances of Board are not intended to be immutable. As the user clicks on different cells of the puzzle, the internal fields in the Board instance should change to reflect the new state. For example, if the user clicks on a cell to change it to be shaded, a field modification must take place inside th**e Board instance to reflect that the cell is now shaded. This can be accomplished via the toggleCellShaded() and toggleCellEliminated() methods. Model The Model interface represents the model of MVC, and therefore contains all data necessary to display the current state of the application. In particular, a Model instance should encapsulate the following concepts: 1. A library of available nonogram puzzles for the user to solve 2. A way to select which puzzle is currently active; for example, maybe an index into the puzzle library 3. The Clues and corresponding Board information for the currently active puzzle 4. A List of active model observers, represented by the ModelObserver interface (see below) Notice that the Model interface extends both Board and Clues. That’s because, per #3, a Model should represent the currently active Board and Clues for the currently active puzzle. There are multiple ways to encapsulate a library of available puzzles. One way is to simply encapsulate a List field to store the list of available puzzle Clues, and then re-initialize the encapsulated Board field(s) every time the user changes the active puzzle. This approach works but has a disadvantage: every time the user changes the active puzzle, their progress on the old puzzle will be forgotten. If you want your app to retain the user’s progress when switching between puzzles, you’ll have to encapuslate that information in your library somehow. One option is to create a new class, maybe called Puzzle, to encapsulate a Clues instance together with the corresponding Board fields for that puzzle. Then, you can store a List of Puzzle instances as your library, and keep track of the Clues for each puzzle along with the corresponding Board information. ModelImpl You must create a class named ModelImpl in the model package which implements the Model interface. This is required for your submission to be autograded. The ModelImpl class should expose a constructor with the following signature: java public ModelImpl(List clues) { // Constructor code here } The clues parameter is a list of Clues instances representing the library of available puzzles for the user to solve. In order to implement the isSolved() method, you’ll have to devise an algorithm to check whether the current state of the Board satisfies the corresponding Clues. This can be tricky, and will probably take some time to get right. The ModelImpl class should be a “subject” with respect to the observer design pattern. This is because your view class will likely register itself as an active observer of the model, and will re-render itself in response to model changes. See the ModelObserver interface below for more information about how to implement this. ModelObserver the ModelObserver interface defines a single method, update(), and is used together with the ModelImpl class to implement the observer design pattern. ModelImpl should therefore notify its active observers whenever any Model field value is changed. Hint: Below is a list of all Model interface methods. Exactly 4 of the 18 methods involve manipulating the state of the Model instance (not including addObserver() and removeObserver()); these 4 methods should therefore trigger the observer notify process. “` Model methods: 1. int getPuzzleCount(); 2. int getPuzzleIndex(); 3. void setPuzzleIndex(int index); 4. void addObserver(ModelObserver observer); 5. void removeObserver(ModelObserver observer); 6. boolean isSolved(); Model methods inherited from Board: 7. boolean isShaded(int row, int col); 8. boolean isEliminated(int row, int col); 9. boolean isSpace(int row, int col); 10. void toggleCellShaded(int row, int col); 11. void toggleCellEliminated(int row, int col); 12. void clear(); Model methods inherited from Clues: 13. int getWidth(); 14. int getHeight(); 15. int[] getRowClues(int index); 16. int[] getColClues(int index); 17. int getRowCluesLength(); 18. int getColCluesLength(); “` Controller All code related to the application’s controller should be placed in the controller package. Remember, the controller package in MVC is intended to act as the “glue” between the model and the view. You are free to implement your controller as you see fit; the controller is not graded by the autograder. Instead, the controller will be manually graded when a learning assistant tries to play your game by running the Main.main() method! However, to help you get started, an interface named Controller has been provided as a starting point. If you decide to use this interface, here’s how you might use it. First, add a new class called ControllerImpl to the controller package which implements the Controller interface. This class should encapsulate a single field: a Model instance. Add a constructor to the ControllerImpl class that looks something like this: java public Controller(Model model) { // Constructor code goes here } The ControllerImpl object should “wrap” a Model instance. Most of the Controller methods will simply be delegated/forwarded directly to the encapsulated Model instance. However, a few methods, like prevPuzzle(), nextPuzzle, and randPuzzle(), will require a few lines of code to get right. View All code related to the application’s view should be placed in the view package. Remember, the view package in MVC is intended to hold all code related to the GUI. You are free to implement your view as you see fit; the view is not graded by the autograder. Instead, the view will be manually graded when a learning assistant tries to play your game by running the Main.main() method! Regardless of the structure that you use for your view, you are required to use JavaFX as your GUI library. Therefore, the code in the view package will primarily create and manipulate JavaFX objects. To help you get started and figure out a good structure for your app, one class (AppLauncher) and one interface (FXComponent) are provided. AppLauncher By default, this class is the launching point of your application (although you can change that if you’d like). The Main class is set up to forward to AppLauncher, which extends Application and therefore launches the JavaFX GUI. To write the view, you’ll need to fill in the start() method in AppLauncher to actually set up and create your UI. Inside the start() method, you should create a Model object and a Controller object. You can use the provided PuzzleLibrary class to get a simple puzzle library for setting up the model. FXComponent Although you could put all your UI generation code directly in the start() method of AppLauncher, this might not be a good idea since it would clutter the method with a lot of JavaFX code. Instead, a better idea is to encapsulate each section of the UI in a separate class. In GUI programming, it’s common to call each “section” of the UI a “component”. To this end, a (suggested) interface, named FXComponent, has been provided. You can use FXComponent to break up your interface into different smaller components. For instance, one FXComponent class, called PuzzleView, might display the clues and the game board inside a GridPanel. Another FXComponent class, called ControlView, might display the puzzle controls, including buttons, to move through the puzzle library. Finally, you might make a third FXComponent class, called MessageView, to show the “success” message when the user successfully finishes the puzzle. Finally, the view must react to user actions, such as clicking on certain user interface elements. Do this by registering observers on the relevant JavaFX UI component events. Sometimes, an application state change is necessary in response to a user action. For example, if the user clicks the “next puzzle” button, the model must be instructed to go to the next puzzle. Make use of the controller’s methods to do this. By utilizing the controller, you will enforce separation of concerns between your model and view, and enforce that the controller is an intermediary between the two.