Ø3.2: Modellering af en PC En PC består af en CPU og et bundkort: CPU er har følgende parametre: Slottypen: Slot A, Slot 1, Socket 7 Clockfrekvensen: 900 MHz, 1000 MHz, 1100MHz, 1200 MHz Modellen: Pentium III, Pentium IV, AMD K7 Der findes følgende CPU er: Slot Freq Model Slot A 900 MHz Pentium III Slot A 1000 MHz Pentium III Slot 1 1000 MHz Pentium IV Socket 7 900 MHz AMD K7 Socket 7 1100 MHz AMD K7 ITU/DTU 30. Marts 2004 1
Ø3.2: Modellering af en PC Bundkort har følgende parametre: Model: ASUS, Aopen, ATX, Acorp Socket typen Maximal clock frekvens antal ram-slots Der findes følgende bundkort: Model Socket MaxFreq N_ram ASUS Slot 1 1000 MHz 3 ASUS Slot A 800 MHz 2 ATX Socket 7 1200MHz 2 Acorp Slot 1 1100 MHz 3 Acorp Slot A 900 MHz 2 ITU/DTU 30. Marts 2004 2
Ø3.2: Modellering af en PC Opgave A: Lav en produkt model der repræsenterer de legale kombinationer af en CPU og et bundkort med hensyn til socket/slot typer og frekvens, således at: CPU ens socket skal være identisk med bundkortets slot. CPU ens clockfrekvens må maximalt være bundkortets MaxFreq. Compiler produkt modellen og check den med pmview. ITU/DTU 30. Marts 2004 3
Løsningsforslag, Ø3.2A type Slot : [ "Slot A", "Slot 1", "Socket 7" ]; Freq : [ "800 MHz", "900 MHz", "1000 MHz", "1100 MHz", "1200 MHz" ]; variable cpu: { model: [ "Pentium III", "Pentium IV", "AMD K7" ]; freq : Freq; slot : Slot; mb: { model: [ ASUS, ATX, Acorp ]; max_freq: Freq; slot: Slot; n_ram: [ 0.. 5 ]; ITU/DTU 30. Marts 2004 4
Løsningsforslag, Ø3.2A #define mk_cpu(m,f,s) (cpu.model = m and cpu.freq = f and cpu.slot = s) rule /* Available CPU's: */ mk_cpu("pentium III", "900 MHz", "Slot A") or mk_cpu("pentium III", "1000 MHz", "Slot A") or mk_cpu("pentium IV", "1000 MHz", "Slot 1") or mk_cpu("amd K7", "900 MHz", "Socket 7") or mk_cpu("amd K7", "1100 MHz", "Socket 7"); ITU/DTU 30. Marts 2004 5
Løsningsforslag, Ø3.2A rule /* Availbale Motherboards */ mb.model = ASUS and mb.max_freq = "1000 MHz" and mb.slot = "Slot 1" and mb.n_ram = 3 or mb.model = ASUS and mb.max_freq = "800 MHz" and mb.slot = "Slot A" and mb.n_ram = 2 or mb.model = ATX and mb.max_freq = "1200 MHz" and mb.slot = "Socket 7" and mb.n_ram = 2 or mb.model = Acorp and mb.max_freq = "1100 MHz" and mb.slot = "Slot 1" and mb.n_ram = 3 or mb.model = Acorp and mb.max_freq = "900 MHz" and mb.slot = "Slot A" and mb.n_ram = 2; /* Sockets must match */ mb.slot = cpu.slot; /* Frequencies must match */ order( cpu.freq ) <= order( mb.max_freq ); ITU/DTU 30. Marts 2004 6
Ø3.2: Flere CPU er og Motherboards Opgave B: Udvid PC en: Omskriv modellen således, at der er muligt at lave flere CPU og Motherboard instanser, hvor reglerne gælder Omskriv modellen, så der er muligt at konfigurere flere PCer. Simplificér brugen af konfiguratoren således, at brugeren ikke bliver spurgt om CPU socket type og maksimum frekvens på motherboard ITU/DTU 30. Marts 2004 7
Løsningsforslag, Ø3.2B Type Slot : [ "Slot A", "Slot 1", "Socket 7" ]; Freq : [ "800 MHz", "900 MHz", "1000 MHz", "1100 MHz", "1200 MHz" ]; Cpu: { /* Make variables irrelevant for user private */ public model : [ "Pentium III", "Pentium IV", "AMD K7" ]; public freq : Freq; private slot : Slot; rule /* Rules are in structural type */ /* Available CPU's: */ model = "Pentium III" and freq = "900 MHz" and slot = "Slot A" or model = "Pentium III" and freq = "1000 MHz" and slot = "Slot A" or model = "Pentium IV" and freq = "1000 MHz" and slot = "Slot 1" or model = "AMD K7" and freq = "900 MHz" and slot = "Socket 7" or model = "AMD K7" and freq = "1100 MHz" and slot = "Socket 7"; ITU/DTU 30. Marts 2004 8
Løsningsforslag, Ø3.2B type Mb: { /* Make variables irrelevant for user private */ public model : [ ASUS, ATX, Acorp ]; private max_freq : Freq; private slot : Slot; private n_ram : [ 0.. MAX_RAM_BLOCKS ]; private ram_type : RamType; rule /* Rules are in structural type */ /* Availbale Motherboards */ model=asus and max_freq="1000 MHz" and slot="slot 1" and n_ram=3 or model=asus and max_freq="800 MHz" and slot="slot A" and n_ram=2 or model=atx and max_freq="1200 MHz" and slot="socket 7" and n_ram=2 or model=acorp and max_freq="1100 MHz" and slot="slot 1" and n_ram=3 or model=acorp and max_freq="900 MHz" and slot="slot A" and n_ram=2; /* Ram compability. NOTE : could be modeled by adding conjunction to each disjunctive row above */ if model = ASUS then ram_type = SD_RAM; if model = ATX then ram_type = SD_RAM; if model = Acorp then ram_type = DDR_RAM; ITU/DTU 30. Marts 2004 9
Ø3.2: Ekstraudstyr Opgave C: Man kan få tre typer CPU kølere : Silverado, Golden Orb og Volcano. Tilføj CPU køler som valgbar ekstra udstyr til PCen. Man skal have en CPU køler hvis CPU frekvensen er over 1000 MHz Silverado blæseren passer på Socket 7 type CPUer, de andre blæsere passer på Slot 1 og Slot A ITU/DTU 30. Marts 2004 10
Løsningsforslag, Ø3.2C Type Cooler : { /* Make variables irrelevant for user private */ public model : [ Silverado, "Golden Orb", Volcano ]; Pc : { /* It is possible to have multiple PC's */ public mb : Mb; public cpu : Cpu; public cooler : optional Cooler; rule /* CPU Cooler is present if freq > 1000 MHZ */ if order(cpu.freq) > order("1000 MHz") then cooler = SOME; /* Cooler must match CPU slot type. NOTE : model, so that we can expand example with more cooler models and CPU slot types! */ if cooler.some.model = Silverado then cpu.slot = "Socket 7"; if cooler.some.model = "Golden Orb" then cpu.slot = "Slot A" or cpu.slot = "Slot 1"; if cooler.some.model = Volcano then cpu.slot = "Slot A" or cpu.slot = "Slot 1"; ITU/DTU 30. Marts 2004 11
Ø3.2: Tilføj RAM RAM blokke har følgende parametre RAM type : SD_RAM, DDR_RAM Kapacitet : 128mb, 256mb, 512mb Der findes følgende RAM blokke RAM type SD_RAM SD_RAM SD_RAM DDR_RAM DDR_RAM Kapacitet 128 mb 256 mb 512 mb 128 mb 512 mb ITU/DTU 30. Marts 2004 12
Ø3.2: Tilføj RAM Opgave D: Tilføj følgende RAM kompabilitet information til Motherboard ASUS bundkort bruger SD_RAM ATX bundkort bruger SD_RAM Acorp bundkort bruger DDR_RAM Tilføj ramblokke til PCen. Hint: der kan være op til 5 ramblokke Typen på hver RAM blok skal passe til den type RAM blokke motherboardet tager Man kan ikke have flere RAM blokke end der kan sidde på motherboardet. Hint: gør RAM blokke optionals, brug SUM operator RAM blokke skal tilføjes først til slot 0, så til slot 1, så til. Indfør en parameter der beskriver den totale mængde RAM. Hint: Indfør en 0 mb kapacitet, kan gøres med enum type. ITU/DTU 30. Marts 2004 13
Løsningsforslag, Ø3.2D constant MAX_RAM_BLOCKS : 5; type Slot : [ "Slot A", "Slot 1", "Socket 7" ]; Freq : [ "800 MHz", "900 MHz", "1000 MHz", "1100 MHz", "1200 MHz" ]; RamType : [ SD_RAM, DDR_RAM ]; /* Capacity is increased in steps of 128 mb */ RamCapacity : [ "0 mb", "128 mb", "256 mb", "384", "512 mb", "640 mb", "768 mb", "896 mb", "1024 mb", "1152 mb", "1280 mb", "1408 mb", "1536 mb" ]; Ram : { ram_type : RamType; capacity : RamCapacity; ITU/DTU 30. Marts 2004 14
Løsningsforslag, Ø3.2D type Pc : { /* It is possible to have multiple PC's */ public mb : Mb; public cpu : Cpu; public cooler : optional Cooler; public ram : array MAX_RAM_BLOCKS of optional Ram; public total_ram : RamCapacity; rule /* Type of RAM must match type of RAM accepted by motherboard */ forall i in [0.. MAX_RAM_BLOCKS - 1] : ( ram[i].some.ram_type = mb.ram_type ); /* There can be no more RAM blocks than can fit on motherboard */ sum i in [0.. MAX_RAM_BLOCKS - 1] : ( if ram[i] = SOME then 1 else 0 ) <= mb.n_ram; /* RAM blocks are filled in from slot 0 and upwards */ forall i in [1.. MAX_RAM_BLOCKS - 1] : ( if ram[i] = SOME then forall j in [0.. i - 1] : (ram[j] = SOME) ); /* Calculate total RAM capacity */ order(total_ram) = sum i in [0.. MAX_RAM_BLOCKS - 1] : ( if ram[i] = SOME then order(ram[i].some.capacity) else order("0 mb") ); ITU/DTU 30. Marts 2004 15