diff --git a/Algoritmi_2/Laboratorio/Lab9/Es2/.gitignore b/Algoritmi_2/Laboratorio/Lab9/Es2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f68d1099657e34d4e7a68aadc730b3ecad84667d --- /dev/null +++ b/Algoritmi_2/Laboratorio/Lab9/Es2/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Algoritmi_2/Laboratorio/Lab9/Es2/Es2.iml b/Algoritmi_2/Laboratorio/Lab9/Es2/Es2.iml index c90834f2d607afe55e6104d8aa2cdfffb713f688..31ddca12075932b7f2f9ca5ab93fa30b7e444019 100644 --- a/Algoritmi_2/Laboratorio/Lab9/Es2/Es2.iml +++ b/Algoritmi_2/Laboratorio/Lab9/Es2/Es2.iml @@ -7,5 +7,16 @@ </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/../../graphLib.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MODULE_DIR$/../../graphLib.jar!/doc" /> + </JAVADOC> + <SOURCES /> + </library> + </orderEntry> </component> </module> \ No newline at end of file diff --git a/Algoritmi_2/Laboratorio/Lab9/Es2/src/DB.java b/Algoritmi_2/Laboratorio/Lab9/Es2/src/DB.java new file mode 100644 index 0000000000000000000000000000000000000000..c1f4ff44b882220d3981e29ad7686a52109d31ec --- /dev/null +++ b/Algoritmi_2/Laboratorio/Lab9/Es2/src/DB.java @@ -0,0 +1,58 @@ +import it.uniupo.algoTools.MaxHeap; + +import java.util.Arrays; + +public class DB { + private final double capacity; + private final int[] dim; + private final double[] time; + + public DB(int[] dim, double[] time) { + this.capacity = dim.length; + this.dim = dim; + this.time = time; + } + + + private double fracKnapsackImpl(double[] dose, double[] quant) { + double valTot = 0; + double remaningSpace = capacity; + + MaxHeap<Integer, Double> maxHeap = new MaxHeap<>(); + + for (int i = 0; i < dose.length; ++i) { + maxHeap.add(i, time[i] / dim[i]); + } + + while (!maxHeap.isEmpty() && remaningSpace > 0) { + // Estraggo il materiale con valore unitario massimo + int extractedMaterial = maxHeap.extractMax(); + + //Se posso prendererlo tutto senza riempite lo zaiono lo prendo tutto + if (remaningSpace >= dim[extractedMaterial]) { + dose[extractedMaterial] = 1; + quant[extractedMaterial] = dim[extractedMaterial]; + valTot += dim[extractedMaterial]; + } + //Altrimenti ne prendo una frazione + else { + dose[extractedMaterial] = remaningSpace / dim[extractedMaterial]; + quant[extractedMaterial] = remaningSpace; + valTot += (time[extractedMaterial] * dose[extractedMaterial]); + } + remaningSpace -= quant[extractedMaterial]; + } + return valTot; + } + + public double timeToRebuild(int memSpace) { + if (memSpace < 0) { + throw new IllegalArgumentException("MemSpace negativo"); + } + double[] dose = new double[memSpace]; + double[] quant = new double[memSpace]; + } + +} + + diff --git a/Algoritmi_2/Laboratorio/Lab9/Es2/src/Main.java b/Algoritmi_2/Laboratorio/Lab9/Es2/src/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..3e59c38fbd57497a72e78859efacc67ac75869da --- /dev/null +++ b/Algoritmi_2/Laboratorio/Lab9/Es2/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/Reti/Laboratorio/Assigment4/EchoServer/client b/Reti/Laboratorio/Assigment4/EchoServer/client deleted file mode 100755 index daed40002f88652868921c748acf1f5e31b6aed3..0000000000000000000000000000000000000000 Binary files a/Reti/Laboratorio/Assigment4/EchoServer/client and /dev/null differ diff --git a/Reti/Laboratorio/Assigment4/EchoServer/client.c b/Reti/Laboratorio/Assigment4/EchoServer/client.c deleted file mode 100644 index c62a1760e1d98569846a0d16d2737991999f59ad..0000000000000000000000000000000000000000 --- a/Reti/Laboratorio/Assigment4/EchoServer/client.c +++ /dev/null @@ -1,75 +0,0 @@ -#include <arpa/inet.h> -#include <netdb.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/socket.h> -#include <sys/types.h> -#include <unistd.h> - -int main(int argc, char *argv[]) { - char valueToSend[256] = {'\0'}; - char valueToReceive[256] = {'\0'}; - printf("-1 per uscire\n"); - while (valueToSend[0] != '-' && valueToSend[1] != '1') { - - int simpleSocket = 0; - int simplePort = 0; - int returnStatus = 0; - char buffer[256] = ""; - struct sockaddr_in simpleServer; - - if (argc != 3) { - fprintf(stderr, "Usage: %s <server> <port>\n", argv[0]); - exit(1); - } - - /* create a streaming socket */ - simpleSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - - if (simpleSocket == -1) { - fprintf(stderr, "Could not create a socket!\n"); - exit(1); - } else { - fprintf(stderr, "Socket created!\n"); - } - - /* retrieve the port number for connecting */ - simplePort = atoi(argv[2]); - - /* setup the address structure */ - /* use the IP address sent as an argument for the server address */ - // bzero(&simpleServer, sizeof(simpleServer)); - memset(&simpleServer, '\0', sizeof(simpleServer)); - simpleServer.sin_family = AF_INET; - // inet_addr(argv[2], &simpleServer.sin_addr.s_addr); - simpleServer.sin_addr.s_addr = inet_addr(argv[1]); - simpleServer.sin_port = htons(simplePort); - - /* connect to the address and port with our socket */ - returnStatus = connect(simpleSocket, (struct sockaddr *)&simpleServer, - sizeof(simpleServer)); - - if (returnStatus == 0) { - fprintf(stderr, "Connect successful!\n"); - } else { - fprintf(stderr, "Could not connect to address!\n"); - close(simpleSocket); - exit(1); - } - - /* get the message from the server */ - // returnStatus = read(simpleSocket, buffer, sizeof(buffer)); - - printf("Inserire il valore da voler inviare al server: "); - scanf("%s", valueToSend); - write(simpleSocket, valueToSend, strlen(valueToSend)); - read(simpleSocket, valueToReceive, sizeof(valueToReceive)); - printf("\n\nEcho: %s\n", valueToReceive); - close(simpleSocket); - memset(valueToReceive, 0, sizeof(valueToReceive)); - memset(valueToSend, 0, sizeof(valueToSend)); - } - - return 0; -} diff --git a/Reti/Laboratorio/Assigment4/EchoServer/server b/Reti/Laboratorio/Assigment4/EchoServer/server deleted file mode 100755 index 0394389a781508863d7c29cc4878a5e63f0f2ee7..0000000000000000000000000000000000000000 Binary files a/Reti/Laboratorio/Assigment4/EchoServer/server and /dev/null differ diff --git a/Reti/Laboratorio/Assigment4/EchoServer/server.c b/Reti/Laboratorio/Assigment4/EchoServer/server.c deleted file mode 100644 index c337b3f9eca3a2d7d1a57e44d66257b40b9877e5..0000000000000000000000000000000000000000 --- a/Reti/Laboratorio/Assigment4/EchoServer/server.c +++ /dev/null @@ -1,111 +0,0 @@ -#include <netdb.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/socket.h> -#include <sys/types.h> -#include <time.h> -#include <unistd.h> - -// const char MESSAGE[] = "Guess who's back!\n"; - -int main(int argc, char *argv[]) { - - time_t ticks = time(NULL); - char MESSAGE[28] = {'\0'}; - snprintf(MESSAGE, sizeof(MESSAGE), "%.24s\r\n", ctime(&ticks)); - - int simpleSocket = 0; - int simplePort = 0; - int returnStatus = 0; - struct sockaddr_in simpleServer; - - if (argc < 1 || argc > 2) { - fprintf(stderr, "Usage: %s <port>\n", argv[0]); - exit(1); - } - - simpleSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - - if (simpleSocket == -1) { - - fprintf(stderr, "Could not create a socket!\n"); - exit(1); - - } else { - fprintf(stderr, "Socket created!\n"); - } - - /* retrieve the port number for listening */ - if (argc == 2) { - simplePort = atoi(argv[1]); - if (simplePort < 10000 || simplePort > 12000) { - fprintf(stderr, "Port must be in range [10000, 12000]\n"); - exit(1); - } - } else { - srand(time(NULL)); - simplePort = (rand() % 1999) + 10000; - } - - /* setup the address structure */ - /* use INADDR_ANY to bind to all local addresses */ - memset(&simpleServer, '\0', sizeof(simpleServer)); - simpleServer.sin_family = AF_INET; - simpleServer.sin_addr.s_addr = htonl(INADDR_ANY); - simpleServer.sin_port = htons(simplePort); - - /* bind to the address and port with our socket */ - returnStatus = bind(simpleSocket, (struct sockaddr *)&simpleServer, - sizeof(simpleServer)); - - if (returnStatus == 0) { - fprintf(stderr, "Bind completed on port %d!\n", simplePort); - } else { - fprintf(stderr, "Could not bind to address!\n"); - close(simpleSocket); - exit(1); - } - - /* lets listen on the socket for connections */ - returnStatus = listen(simpleSocket, 5); - - if (returnStatus == -1) { - fprintf(stderr, "Cannot listen on socket!\n"); - close(simpleSocket); - exit(1); - } - - while (1) { - struct sockaddr_in clientName = {0}; - int simpleChildSocket = 0; - int clientNameLength = sizeof(clientName); - - /* wait here */ - - simpleChildSocket = - accept(simpleSocket, (struct sockaddr *)&clientName, &clientNameLength); - - if (simpleChildSocket == -1) { - fprintf(stderr, "Cannot accept connections!\n"); - close(simpleSocket); - exit(1); - } - - /* handle the new connection request */ - /* write out our message to the client */ - - // Read message from client - char bufferRead[256] = {'\0'}; - printf("%zu\n\n", read(simpleChildSocket, bufferRead, sizeof(bufferRead))); - printf("Received: %s\n", bufferRead); - char valueToSend[256] = {'\0'}; - snprintf(valueToSend, sizeof(valueToSend), "%s", bufferRead); - write(simpleChildSocket, valueToSend, sizeof(valueToSend)); - - close(simpleChildSocket); - } - - close(simpleSocket); - return 0; -} diff --git a/Reti/Laboratorio/Assigment4/EchoServer2/client b/Reti/Laboratorio/Assigment4/EchoServer2/client deleted file mode 100755 index daed40002f88652868921c748acf1f5e31b6aed3..0000000000000000000000000000000000000000 Binary files a/Reti/Laboratorio/Assigment4/EchoServer2/client and /dev/null differ diff --git a/Reti/Laboratorio/Assigment4/EchoServer2/makefile b/Reti/Laboratorio/Assigment4/EchoServer2/makefile deleted file mode 100644 index f0ddf2785d27023f6a46168567b61136c6fc91b9..0000000000000000000000000000000000000000 --- a/Reti/Laboratorio/Assigment4/EchoServer2/makefile +++ /dev/null @@ -1,10 +0,0 @@ -all: client server - -client: client.c - gcc client.c -o client - -server: server.c - gcc server.c -o server - -clean: - rm -f client server diff --git a/Reti/Laboratorio/Assigment4/EchoServer2/server b/Reti/Laboratorio/Assigment4/EchoServer2/server deleted file mode 100755 index 0394389a781508863d7c29cc4878a5e63f0f2ee7..0000000000000000000000000000000000000000 Binary files a/Reti/Laboratorio/Assigment4/EchoServer2/server and /dev/null differ diff --git a/Reti/Laboratorio/Assigment4/EchoServer2/client.c b/Reti/Laboratorio/Assigment5/CharCount/client.c similarity index 100% rename from Reti/Laboratorio/Assigment4/EchoServer2/client.c rename to Reti/Laboratorio/Assigment5/CharCount/client.c diff --git a/Reti/Laboratorio/Assigment4/EchoServer/makefile b/Reti/Laboratorio/Assigment5/CharCount/makefile similarity index 100% rename from Reti/Laboratorio/Assigment4/EchoServer/makefile rename to Reti/Laboratorio/Assigment5/CharCount/makefile diff --git a/Reti/Laboratorio/Assigment4/EchoServer2/server.c b/Reti/Laboratorio/Assigment5/CharCount/server.c similarity index 98% rename from Reti/Laboratorio/Assigment4/EchoServer2/server.c rename to Reti/Laboratorio/Assigment5/CharCount/server.c index b13bab718a90bbfdd3d9cdf42e964d27992823c7..6623e4fd0dbb3b7a8949c88a98a1a4c8ecf66034 100644 --- a/Reti/Laboratorio/Assigment4/EchoServer2/server.c +++ b/Reti/Laboratorio/Assigment5/CharCount/server.c @@ -7,8 +7,6 @@ #include <time.h> #include <unistd.h> -// const char MESSAGE[] = "Guess who's back!\n"; - int main(int argc, char *argv[]) { int simpleSocket = 0; int simplePort = 0;