updates that were lying around but never got checked in; includes reorg of gui
[slipway.git] / src / edu / berkeley / slipway / mpar / Placement.java
1 package edu.berkeley.slipway.mpar;
2 import com.atmel.fpslic.*;
3 import java.awt.*;
4 import byucc.edif.tools.merge.*;
5 import byucc.edif.*;
6 import java.io.*;
7 import java.util.*;
8 import edu.berkeley.slipway.*;
9 import edu.berkeley.abits.*;
10 import com.atmel.fpslic.*;
11 import static com.atmel.fpslic.FpslicConstants.*;
12 import static edu.berkeley.slipway.mpar.PhysicalDevice.*;
13 import static edu.berkeley.slipway.mpar.NetList.*;
14
15 public class Placement {
16
17     public final NetList netlist;
18     public final PhysicalDevice pd;
19
20     public HashMap<PhysicalDevice.PhysicalCell, NetList.Node> cellToNode =
21         new HashMap<PhysicalDevice.PhysicalCell, NetList.Node>();
22     public HashMap<NetList.Node, PhysicalDevice.PhysicalCell> nodeToCell =
23         new HashMap<NetList.Node, PhysicalDevice.PhysicalCell>();
24
25     public Placement(NetList netlist, PhysicalDevice pd) {
26         this.netlist = netlist;
27         this.pd = pd;
28     }
29
30     public void unplace(PhysicalDevice.PhysicalCell pc) {
31         NetList.Node n = cellToNode.get(pc);
32         if (n != null) unplace(n);
33     }
34     public void unplace(NetList.Node n) {
35         PhysicalDevice.PhysicalCell pc = nodeToCell.get(n);
36         cellToNode.remove(pc);
37         nodeToCell.remove(n);
38     }
39     public void place(NetList.Node n, PhysicalDevice.PhysicalCell pc) {
40         if (n==null) return;
41         if (pc==null) return;
42         unplace(n);
43         unplace(pc);
44         cellToNode.put(pc, n);
45         nodeToCell.put(n, pc);
46     }
47
48     public void setPlacement() {
49         for(PhysicalDevice.PhysicalCell pc : cellToNode.keySet()) {
50             NetList.Node node = cellToNode.get(pc);
51             pc.place(node);
52         }
53     }
54
55     public boolean isPlaced(NetList.Node n) { return nodeToCell.get(n) != null; }
56     public boolean isPlaced(PhysicalDevice.PhysicalCell pc) { return cellToNode.get(pc) != null; }
57
58     public PhysicalDevice.PhysicalCell nodeToCell(NetList.Node n) { return nodeToCell.get(n); }
59     public NetList.Node cellToNode(PhysicalDevice.PhysicalCell pc) { return cellToNode.get(pc); }
60
61     public void random(Random rand) {
62         for(NetList.Node n : netlist.nodes) {
63             while(true) {
64                 PhysicalDevice.PhysicalCell pc = pd.randomCell(rand);
65                 if (isPlaced(pc)) continue;
66                 place(n, pc);
67                 break;
68             }
69         }
70     }
71
72 }