<jupyter_start><jupyter_text>Linear ProgrammingHere the goal is to show how a constrained problem can be decomposed and solved by ADMM.For this purpose, this notebook considers solving primal and dual linear programming problems.  Primal   minimize: $c^T \; x$\subject to: $A \; x = b$\$\;\;\;\;\;\;\;\;\;\;\;\;\; x \ge 0$  Dual   maximize: $b^T \; y$\subject to: $A^T \; y \ge c$  Duality in Linear Programming $c^T \; x \;\;\; = \;\;\; b^T \; y$  Steps1. Devise a computation graph representing the problem as a bipartite graph2. Implement nodes as Java classes extending org.admm4j.core.Node3. Create the JSON input defining the graph4. Execute admm4j5. Import and analyze results  This notebook uses the AFIRO problem from the NETLIB Linear Programming test setThis problem has 51 variables, 27 constraints and the optimal objective value of -4.6475314286E+02.http://www.netlib.org/lp/data/readmehttp://users.clas.ufl.edu/hager/coap/format.html  Step 1. Devise a computation graph representing the problem as a bipartite graph  The objective node solves a linear objective function.\The constraints are distributed among 4 nodes, with each node treating locally available set of constraints.  Step 2. Implement nodes as Java classes extending org.admm4j.core.Node The following classes are implemented1. org.admm4j.demo.common.LinearFunctionNode.java2. org.admm4j.demo.common.ProjectionNode.java  Step 3. Create the JSON input defining the graphThe JSON input files can be found in the folder __examples_input__.\Because real problems often have inputs with many zeros, examples of sparse formulations are also provided.\Following are the input files for this problem:\__lp_afiro_primal_input.json__\__lp_afiro_dual_input.json__\__lp_sparse_afiro_primal_input.json__\__lp_sparse_afiro_dual_input.json__  Step 4. Execute admm4jThe defined JSON models can be solved by admm4j using command line.  Solve primal problem<jupyter_code>!java -jar admm4j-demo/target/admm4j-demo-1.0-jar-with-dependencies.jar\
           -input admm4j-demo/examples_input/lp_afiro_primal_input.json\
           -output lp_afiro_primal_output.json<jupyter_output><empty_output><jupyter_text>Solve dual problem<jupyter_code>!java -jar admm4j-demo/target/admm4j-demo-1.0-jar-with-dependencies.jar\
           -input admm4j-demo/examples_input/lp_afiro_dual_input.json\
           -output lp_afiro_dual_output.json<jupyter_output><empty_output><jupyter_text>Solve primal problem using sparse formulation<jupyter_code>!java -jar admm4j-demo/target/admm4j-demo-1.0-jar-with-dependencies.jar\
           -input admm4j-demo/examples_input/lp_sparse_afiro_primal_input.json\
           -output lp_sparse_afiro_primal_output.json<jupyter_output><empty_output><jupyter_text>Solve dual problem using sparse formulation<jupyter_code>!java -jar admm4j-demo/target/admm4j-demo-1.0-jar-with-dependencies.jar\
           -input admm4j-demo/examples_input/lp_sparse_afiro_dual_input.json\
           -output lp_sparse_afiro_dual_output.json<jupyter_output><empty_output><jupyter_text>Step 5. Import and analyze resultsThe cell below should be run after running all above cells.<jupyter_code>import json

fin = open('lp_afiro_primal_output.json', 'r')
res = json.loads(fin.read())
fin.close()
print('Primal objective value', res.get('nodesI')[0].get('objective'))

fin = open('lp_afiro_dual_output.json', 'r')
res = json.loads(fin.read())
fin.close()
print('Dual objective value', res.get('nodesI')[0].get('objective'))

fin = open('lp_sparse_afiro_primal_output.json', 'r')
res = json.loads(fin.read())
fin.close()
print('Sparse primal objective value', res.get('nodesI')[0].get('objective'))

fin = open('lp_sparse_afiro_dual_output.json', 'r')
res = json.loads(fin.read())
fin.close()
print('Sparse dual objective value', res.get('nodesI')[0].get('objective'))<jupyter_output>Primal objective value -464.7516256386707
Dual objective value 464.3883697513007
Sparse primal objective value -464.7516256386707
Sparse dual objective value 464.3883697513007
{'fraction_non_alphanumeric': 0.10612855007473841, 'fraction_numerical': 0.03139013452914798, 'mean_word_length': 5.001494768310912, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '295595', 'license': 'MIT', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1296, 'n_words': 338, 'path': 'Example_LinearProgramming.ipynb', 'repo_name': 'romden/admm4j', 'size': '4014'}