Difference between revisions of "Assessment SET08112 2011 Hard"

From Progzoo
Jump to: navigation, search
(Question 11)
(Question 07)
Line 127: Line 127:
 
</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 183: 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 189: 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 239: 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>
  

Revision as of 00:02, 4 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 08

List those items that are in one tower only.


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

Question 09

List the trays by order of weight. Show the heaviest trays first.


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

Question 10

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.


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