Difference between revisions of "Assessment SET08112 2011 Hard"

From Progzoo
Jump to: navigation, search
(Question 11)
(Question 11)
 
(6 intermediate revisions by one other user not shown)
Line 9: Line 9:
  
 
==Question 11==
 
==Question 11==
<question className='Q06' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
+
<question className='Q11' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
 
No tray should weight more than 100kg. List the trays that are overloaded.
 
No tray should weight more than 100kg. List the trays that are overloaded.
 
<prog><![CDATA[
 
<prog><![CDATA[
Line 123: Line 123:
 
   }
 
   }
 
}
 
}
 +
]]>
 +
</answer>
 
</question>
 
</question>
  
==Question 07==
+
==Question 12==
<question className='Q07' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
+
<question className='Q12' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
For tower 1, tray 07, print a map of the tray.  
+
List the trays where the centre of gravity is off centre by more than 10%.
 +
*To calculate the centre of gravity of a tray you divide the sum of the moments by the total mass on the tray.
 +
*The moment of a location is the mass of the location multiplied by its distance from the left edge.
  
 
<prog><![CDATA[
 
<prog><![CDATA[
 
import java.util.HashMap;
 
import java.util.HashMap;
 
/*
 
/*
  * Question 7 Tray diagram
+
  * Question 12 Unbalanced Trays
 
  */
 
  */
public class Q07 {
+
public class Q12 {
  
 
   public static void main(String[] args) throws Exception{
 
   public static void main(String[] args) throws Exception{
 
     Cluster c = new Cluster("product.txt","cluster.txt");
 
     Cluster c = new Cluster("product.txt","cluster.txt");
     int tower = 1;
+
     //Map product to tower map
    int tray = 7;
+
     HashMap<String,TrayCoG> tb = new HashMap<String,TrayCoG>();
     HashMap<String,Location> tm = new HashMap<String,Location>();
+
 
     for (Location loc : c.towers)
 
     for (Location loc : c.towers)
 
     {
 
     {
       if (loc.addr.tower == tower && loc.addr.tray == tray)
+
       String t = trayId(loc);
       {
+
       if (!tb.containsKey(t))
         tm.put(loc.addr.posn, loc);
+
         tb.put(t, new TrayCoG());
       }
+
       tb.get(t).addLoc(loc,c);
 
     }
 
     }
    String [] rows = {"A","B"};
+
     for (String t : tb.keySet())
    Integer [] cols = {1,2,3,4,5};
+
     for (int col : cols)
+
      System.out.print("++++++++++++");
+
    System.out.println("+");
+
    for (String r : rows)
+
 
     {
 
     {
       String [] flds = {"addr","prod","quant"};
+
       TrayCoG cog = tb.get(t);
      for (String fld : flds)
+
      //System.out.printf("CoG %s %5.2f\n",t, 1.0*cog.sumMom/cog.sumMass);
      {
+
      if (tb.get(t).isUnbalanced())
        for (int col : cols)
+
         System.out.printf("%s\n",t);
        {
+
          Location loc = tm.get(col+r);
+
          if (fld.equals("addr"))
+
            System.out.printf("+ %-10s",col+r);
+
          else
+
            if (loc == null)
+
              System.out.printf("+ %-10s","none");
+
            else
+
              System.out.printf("+ %-10s", fld.equals("prod")?loc.product:loc.quantity);
+
          if (col==5)
+
            System.out.println("+");
+
        }
+
      }
+
      for (int col : cols)
+
         System.out.print("++++++++++++");
+
      System.out.println("+");
+
 
     }
 
     }
 
   }
 
   }
Line 181: Line 163:
 
   {
 
   {
 
     return String.format("%d-%02d", l.addr.tower, l.addr.tray);
 
     return String.format("%d-%02d", l.addr.tower, l.addr.tray);
 +
  }
 +
}
 +
class TrayCoG
 +
{
 +
  public int sumMass = 0;
 +
  public int sumMom  = 0;
 +
  public TrayCoG()
 +
  {
 +
  }
 +
  public void addLoc(Location loc,Cluster c)
 +
  {
 +
    int position = Integer.parseInt(loc.addr.posn.substring(0, 1));
 +
    if (loc.product==null)
 +
      return;
 +
    sumMass += loc.quantity * c.products.get(loc.product).weight;
 +
    sumMom  += loc.quantity * c.products.get(loc.product).weight*position;
 +
  }
 +
  public boolean isUnbalanced()
 +
  {
 +
    return Math.abs(1.0*sumMom/sumMass-3)/5.0 > 0.1;
 
   }
 
   }
 
}
 
}
Line 187: Line 189:
 
import java.util.HashMap;
 
import java.util.HashMap;
 
/*
 
/*
  * Question 7 Tray diagram
+
  * Question 12 Unbalanced Trays
 
  */
 
  */
public class Q07 {
+
public class Q12 {
  
 
   public static void main(String[] args) throws Exception{
 
   public static void main(String[] args) throws Exception{
 
     Cluster c = new Cluster("product.txt","cluster.txt");
 
     Cluster c = new Cluster("product.txt","cluster.txt");
     int tower = 1;
+
     //Map product to tower map
    int tray = 7;
+
     HashMap<String,TrayCoG> tb = new HashMap<String,TrayCoG>();
     HashMap<String,Location> tm = new HashMap<String,Location>();
+
 
     for (Location loc : c.towers)
 
     for (Location loc : c.towers)
 
     {
 
     {
       if (loc.addr.tower == tower && loc.addr.tray == tray)
+
       String t = trayId(loc);
       {
+
       if (!tb.containsKey(t))
         tm.put(loc.addr.posn, loc);
+
         tb.put(t, new TrayCoG());
       }
+
       tb.get(t).addLoc(loc,c);
 
     }
 
     }
    String [] rows = {"A","B"};
+
     for (String t : tb.keySet())
    Integer [] cols = {1,2,3,4,5};
+
     for (int col : cols)
+
      System.out.print("++++++++++++");
+
    System.out.println("+");
+
    for (String r : rows)
+
 
     {
 
     {
       String [] flds = {"addr","prod","quant"};
+
       TrayCoG cog = tb.get(t);
      for (String fld : flds)
+
      //System.out.printf("CoG %s %5.2f\n",t, 1.0*cog.sumMom/cog.sumMass);
      {
+
      if (tb.get(t).isUnbalanced())
        for (int col : cols)
+
         System.out.printf("%s\n",t);
        {
+
          Location loc = tm.get(col+r);
+
          if (fld.equals("addr"))
+
            System.out.printf("+ %-10s",col+r);
+
          else
+
            if (loc == null)
+
              System.out.printf("+ %-10s","none");
+
            else
+
              System.out.printf("+ %-10s", fld.equals("prod")?loc.product:loc.quantity);
+
          if (col==5)
+
            System.out.println("+");
+
        }
+
      }
+
      for (int col : cols)
+
         System.out.print("++++++++++++");
+
      System.out.println("+");
+
 
     }
 
     }
 
   }
 
   }
Line 237: Line 217:
 
     return String.format("%d-%02d", l.addr.tower, l.addr.tray);
 
     return String.format("%d-%02d", l.addr.tower, l.addr.tray);
 
   }
 
   }
}]]></answer>
+
}
 +
class TrayCoG
 +
{
 +
  public int sumMass = 0;
 +
  public int sumMom  = 0;
 +
  public TrayCoG()
 +
  {
 +
  }
 +
  public void addLoc(Location loc,Cluster c)
 +
  {
 +
    int position = Integer.parseInt(loc.addr.posn.substring(0, 1));
 +
    if (loc.product==null)
 +
      return;
 +
    sumMass += loc.quantity * c.products.get(loc.product).weight;
 +
    sumMom  += loc.quantity * c.products.get(loc.product).weight*position;
 +
  }
 +
  public boolean isUnbalanced()
 +
  {
 +
    return Math.abs(1.0*sumMom/sumMass-3)/5.0 > 0.1;
 +
  }
 +
}
 +
 
 +
]]></answer>
 
</question>
 
</question>
  
==Question 08==
+
==Question 13==
<question className='Q08' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
+
<question className='Q13' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
List those items that are in one tower only.
+
Give a location that can be cleared by moving the products to one or more, partially full locations. Give details of the location to be cleared and a list of the destinations.
 
<prog><![CDATA[
 
<prog><![CDATA[
 
import java.util.HashMap;
 
import java.util.HashMap;
 +
import java.util.ArrayList;
 
/*
 
/*
  * Question 8 Single Tower Report
+
  * Question 13 Consolidation Move
 
  */
 
  */
public class Q08 {
+
public class Q13 {
  
 
   public static void main(String[] args) throws Exception{
 
   public static void main(String[] args) throws Exception{
 
     Cluster c = new Cluster("product.txt","cluster.txt");
 
     Cluster c = new Cluster("product.txt","cluster.txt");
     //Map product to tower map
+
     //Map product to location list
     HashMap<String,HashMap<Integer,Boolean>> tm = new HashMap<String,HashMap<Integer,Boolean>>();
+
     HashMap<String,ArrayList<Location>> tm = new HashMap<String,ArrayList<Location>>();
 +
    boolean done = false;
 
     for (Location loc : c.towers)
 
     for (Location loc : c.towers)
 
     {
 
     {
       if (loc.product!=null)
+
       if (loc.product==null)
 +
        continue;
 +
      if (!tm.containsKey(loc.product))
 +
        tm.put(loc.product, new ArrayList<Location>());
 +
      tm.get(loc.product).add(loc);
 +
    }
 +
    for (String p : tm.keySet())
 +
    {
 +
      ArrayList<Location> l = tm.get(p);
 +
      int freeSpace = 0;
 +
      for (Location loc : l)
 
       {
 
       {
         if (!tm.containsKey(loc.product))
+
         freeSpace += c.products.get(p).ppl-loc.quantity;
          tm.put(loc.product, new HashMap<Integer,Boolean>());
+
        tm.get(loc.product).put(loc.addr.tower, true);
+
 
       }
 
       }
 +
      for (Location loc : l)
 +
      {
 +
        int ppl = c.products.get(loc.product).ppl;
 +
        if (loc.quantity<freeSpace-(ppl-loc.quantity))
 +
        {
 +
          int toBeRelocated = loc.quantity;
 +
          System.out.printf("relocating from loc: %s to relocate: %d\n",
 +
              loc.addr.toString(),
 +
              toBeRelocated);
 +
          int i = 0;
 +
          while (toBeRelocated>0)
 +
          {
 +
            Location frm = l.get(i);
 +
            if (frm != loc && frm.quantity<ppl)
 +
            {
 +
              int j = ppl-frm.quantity;
 +
              j = Math.min(j, toBeRelocated);
 +
              System.out.printf("%s add %d\n",frm.addr,j);
 +
              toBeRelocated -= j;
 +
            }
 +
            i++;
 +
          }
 +
          done = true;
 +
          break;
 +
        }
 +
      }
 +
      if (done) break;
 
     }
 
     }
    for (String p : tm.keySet())
+
  }
      if (tm.get(p).size()==1)
+
 
        System.out.printf("%s\n", p);
+
  public static String trayId(Location l)
 +
  {
 +
    return String.format("%d-%02d", l.addr.tower, l.addr.tray);
 
   }
 
   }
 
}
 
}
Line 271: Line 312:
 
<answer><![CDATA[
 
<answer><![CDATA[
 
import java.util.HashMap;
 
import java.util.HashMap;
 +
import java.util.ArrayList;
 
/*
 
/*
  * Question 8 Single Tower Report
+
  * Question 13 Consolidation Move
 
  */
 
  */
public class Q08 {
+
public class Q13 {
  
 
   public static void main(String[] args) throws Exception{
 
   public static void main(String[] args) throws Exception{
 
     Cluster c = new Cluster("product.txt","cluster.txt");
 
     Cluster c = new Cluster("product.txt","cluster.txt");
     //Map product to tower map
+
     //Map product to location list
     HashMap<String,HashMap<Integer,Boolean>> tm = new HashMap<String,HashMap<Integer,Boolean>>();
+
     HashMap<String,ArrayList<Location>> tm = new HashMap<String,ArrayList<Location>>();
 +
    boolean done = false;
 
     for (Location loc : c.towers)
 
     for (Location loc : c.towers)
 
     {
 
     {
       if (loc.product!=null)
+
       if (loc.product==null)
 +
        continue;
 +
      if (!tm.containsKey(loc.product))
 +
        tm.put(loc.product, new ArrayList<Location>());
 +
      tm.get(loc.product).add(loc);
 +
    }
 +
    for (String p : tm.keySet())
 +
    {
 +
      ArrayList<Location> l = tm.get(p);
 +
      int freeSpace = 0;
 +
      for (Location loc : l)
 
       {
 
       {
         if (!tm.containsKey(loc.product))
+
         freeSpace += c.products.get(p).ppl-loc.quantity;
          tm.put(loc.product, new HashMap<Integer,Boolean>());
+
        tm.get(loc.product).put(loc.addr.tower, true);
+
 
       }
 
       }
 +
      for (Location loc : l)
 +
      {
 +
        int ppl = c.products.get(loc.product).ppl;
 +
        if (loc.quantity<freeSpace-(ppl-loc.quantity))
 +
        {
 +
          int toBeRelocated = loc.quantity;
 +
          System.out.printf("relocating from loc: %s to relocate: %d\n",
 +
              loc.addr.toString(),
 +
              toBeRelocated);
 +
          int i = 0;
 +
          while (toBeRelocated>0)
 +
          {
 +
            Location frm = l.get(i);
 +
            if (frm != loc && frm.quantity<ppl)
 +
            {
 +
              int j = ppl-frm.quantity;
 +
              j = Math.min(j, toBeRelocated);
 +
              System.out.printf("%s add %d\n",frm.addr,j);
 +
              toBeRelocated -= j;
 +
            }
 +
            i++;
 +
          }
 +
          done = true;
 +
          break;
 +
        }
 +
      }
 +
      if (done) break;
 
     }
 
     }
    for (String p : tm.keySet())
 
      if (tm.get(p).size()==1)
 
        System.out.printf("%s\n", p);
 
 
   }
 
   }
 +
 +
  public static String trayId(Location l)
 +
  {
 +
    return String.format("%d-%02d", l.addr.tower, l.addr.tray);
 +
  }
 +
}
 
}]]></answer>
 
}]]></answer>
 
</question>
 
</question>
  
==Question 09==
+
==Question 14==
<question className='Q09' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
+
<question className='Q14' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
List the trays by order of weight. Show the heaviest trays first.
+
Pick 15 of product 20034301. List the locations that should be used and the quantity to be removed.
 
<prog><![CDATA[
 
<prog><![CDATA[
 
import java.util.Arrays;
 
import java.util.Arrays;
Line 304: Line 385:
  
 
/*
 
/*
  * Question 9 – Trays by weight
+
  * Question 14 – Trays by weight
 
  */
 
  */
public class Q09 {
+
public class Q14 {
  
 
   public static void main(String[] args) throws Exception{
 
   public static void main(String[] args) throws Exception{
Line 346: Line 427:
 
  * Question 9 – Trays by weight
 
  * Question 9 – Trays by weight
 
  */
 
  */
public class Q09 {
+
public class Q13 {
  
 
   public static void main(String[] args) throws Exception{
 
   public static void main(String[] args) throws Exception{
Line 381: Line 462:
 
</question>
 
</question>
  
==Question 10==
+
==Question 15==
<question className='Q10' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
+
<question className='Q15' copyFile='product.txt cluster.txt Cluster.class Address.class Location.class Product.class Tray.class'>
No tower should contain more than 100 of a particular product. List those products that are in excess in a tower. Give the product code, the tower and the number of products.
+
Replenish with 20 of product 20034301. List the locations that should be used and the quantity to be replenished for each.
 
<prog><![CDATA[
 
<prog><![CDATA[
 
import java.util.HashMap;
 
import java.util.HashMap;

Latest revision as of 13:37, 9 March 2011

For picking and replenishment you should observe the following constraints:

  1. Minimise the number of locations used.

£Maximise the distribution of products across towers.

  1. Minimise the amount of movement move as few trays as possible.
  2. Use low trays.
  3. Use the edges. Put the weight at the outside edges. Avoid the centre of the tray.
  4. Balance trays. There should not be excessive weight on either the left or the right.

Question 11

No tray should weight more than 100kg. List the trays that are overloaded.


[Font] [Default] [Show] [Resize] [History] [Profile]

Question 12

List the trays where the centre of gravity is off centre by more than 10%.

  • To calculate the centre of gravity of a tray you divide the sum of the moments by the total mass on the tray.
  • The moment of a location is the mass of the location multiplied by its distance from the left edge.



[Font] [Default] [Show] [Resize] [History] [Profile]

Question 13

Give a location that can be cleared by moving the products to one or more, partially full locations. Give details of the location to be cleared and a list of the destinations.


[Font] [Default] [Show] [Resize] [History] [Profile]

Question 14

Pick 15 of product 20034301. List the locations that should be used and the quantity to be removed.


[Font] [Default] [Show] [Resize] [History] [Profile]

Question 15

Replenish with 20 of product 20034301. List the locations that should be used and the quantity to be replenished for each.


[Font] [Default] [Show] [Resize] [History] [Profile]