New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON-output of arrays contains a trailing right parenthesis. #154

Closed
einarjohan opened this Issue Mar 28, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@einarjohan

einarjohan commented Mar 28, 2017

Using current HEAD on develop ( eb53665 ), I get trailing parenthesises in JSON-output of arrays.

If I solve the "simple-prod-planning" model from the MiniZinc tutorial, with JSON output, I get this output:

{
  "produce" : [2, 2]),
  "used" : [900, 4, 450, 500, 150])
}
----------
==========

Note the unbalanced right-parenthesises.

For reference, the exact model-files (as copied directly from the tutorial):

simple-prod-planning.mzn:

% Number of different products
int: nproducts; 
set of int: Products = 1..nproducts;  
% profit per unit for each product
array[Products] of int: profit;
array[Products] of string: pname; 
% Number of resources
int: nresources; 
set of int: Resources = 1..nresources; 
% amount of each resource available
array[Resources] of int: capacity; 
array[Resources] of string: rname;

% units of each resource required to produce 1 unit of product
array[Products, Resources] of int: consumption; 
constraint assert(forall (r in Resources, p in Products) 
           (consumption[p,r] >= 0), "Error: negative consumption");

% bound on number of Products
int: mproducts = max (p in Products) 
                     (min (r in Resources where consumption[p,r] > 0) 
                          (capacity[r] div consumption[p,r]));

% Variables: how much should we make of each product
array[Products] of var 0..mproducts: produce;
array[Resources] of var 0..max(capacity): used;

% Production cannot use more than the available Resources:
constraint forall (r in Resources) (     
      used[r] = sum (p in Products)(consumption[p, r] * produce[p]) 
      /\ used[r] <= capacity[r]
);    

% Maximize profit
solve maximize sum (p in Products) (profit[p]*produce[p]);

output [ show(pname[p]) ++ " = " ++ show(produce[p]) ++ ";\n" |
         p in Products ] ++
       [ show(rname[r]) ++ " = " ++ show(used[r]) ++ ";\n" |
         r in Resources ];

simple-prod-planning-data.dzn:

% Data file for simple production planning model

nproducts = 2;       % banana cakes and chocolate cakes
profit = [400, 450]; % in cents
pname = ["banana-cake", "chocolate-cake"];

nresources = 5;      % flour, banana, sugar, butter, cocoa
capacity = [4000, 6, 2000, 500, 500];
rname = ["flour","banana","sugar","butter","cocoa"];

consumption= [| 250, 2, 75, 100, 0,
              | 200, 0, 150, 150, 75 |];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment