public void build(Format f, ArrayList<String> regions)
          throws IOException
    {
        final int nregion = regions.size();

        data = new AnchorData[(nregion  + 2) * 4];
        for(int i = 0; i < data.length; i++) {
            data[i] = new AnchorData();
            data[i].target = i;
            data[i].index  = i;
        }

        // add screen & format
        data[0].value = data[0+4].value = 0;
        data[1].value = data[1+4].value = 0;
        data[2].value = data[2+4].value = f.w;
        data[3].value = data[3+4].value = f.h;

        for(int i = 0; i < nregion; i++) {
            final RegionData child = f.getRegion( regions.get(i));
            for(int j = 0; j < 4; j++) {
                final int index1 = 8 + 4 * i + j;
                final int target = child.targets[j];
                final int type = child.types[j];
                final int index2 = 4 * target + (j & 1)
                      + (type == RegionData.TYPE_P0 ? 0 : 2);

                if(index1 == index2)
                    throw new IOException("Bad anchor in " + child.getName() );

                data[index1].value = child.values[j];
                data[index1].region = child;
                add_dep(data[index2], data[index1]);
            }
        }


        for(int i = 0; i < 8; i++)
            add_order_rec(data[i], 1);

        for(int i = 0; i < 8; i++)
            compute_diff_rec(data[i], 0);

        // sort after assignment order
        Arrays.sort(data, 8, data.length, AnchorData.comparator);
    }