Schaltwerk 2024-12-10

Post Reply
User avatar
david
Site Admin
Posts: 30
Joined: Fri Sep 13, 2024 9:38 pm

Schaltwerk 2024-12-10

Post by david »

Komplexes Schaltwerk - das steuerwerk ist nicht 100% richtig, aber das ist gerade egal
Attachments
asm20241210b-1.jpg
asm20241210b-1.jpg (52.26 KiB) Viewed 948 times
asm20241210.jpg
asm20241210.jpg (41.75 KiB) Viewed 949 times
asm20241210operationswerk.jpg
asm20241210operationswerk.jpg (39.08 KiB) Viewed 949 times
User avatar
david
Site Admin
Posts: 30
Joined: Fri Sep 13, 2024 9:38 pm

Re: Schaltwerk 2024-12-10

Post by david »

Kein Komplexes Schaltwerk, anderes uebungsprogramm als sonst

Uebungsprogramm

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>



#define MAX_SPECIAL_STATES      3
#define MAX_STATES              4
#define MIN_STATE               1
#define SPECIAL_STATE_1         1
#define SPECIAL_STATE_2         2
#define SPECIAL_STATE_3         3
#define MAX_INPUTS              2

void printraw (int a [], int b [], int y []) {
    int i;
    printf ("Zustand\t\tFolge-Zustand fuer\tAusgang\n");
    printf ("\t\t\tx=0\tx=1\t\t\t\t\n");

    for (i = MIN_STATE;  i < (MAX_STATES + MIN_STATE);  i++)
        printf ("%i\t\t\t%i\t%i\t\t\t\t%i\n", i, a [i - MIN_STATE], b [i - MIN_STATE], y [i - MIN_STATE]);


return;
}

void printcsv (int a [], int b [], int y []) {
    int i;
    printf ("Zustand,FolgeZustandx=0,FolgeZustandx=1,Ausgabe\n");

    for (i = MIN_STATE;  i < (MAX_STATES + MIN_STATE);  i++)
        printf ("%i,%i,%i,%i\n", i, a [i - MIN_STATE], b [i - MIN_STATE], y [i - MIN_STATE]);

return;
}

void printtex (int a [], int b [], int y []) {
    int i;
    printf ("\\documentclass [a4paper]{article}\n");
    printf ("\\usepackage{german}\n");
    printf ("\\begin{document}\n");
    printf ("\\begin{tabular}{|c||c|c||c|}");
    printf ("\\hline\n");
    printf ("Zustand & \\multicolumn {2}{||c||}{Folge-Zustand fuer}& Ausgang\\\\\n");
    printf ("\\hline\n");
    printf ("& \\verb\"x=0\" & \\verb\"x=1\" &\\\\\n");
    printf ("\\hline\n");
    printf ("\\hline\n");

    for (i = MIN_STATE;  i < (MAX_STATES + MIN_STATE);  i++) {
        printf ("%i & %i & %i & %i\\\\\n", i, a [i - MIN_STATE], b [i - MIN_STATE], y [i - MIN_STATE]);
        printf ("\\hline\n");
    }
    printf ("\\end{tabular}\n");
    printf ("\\end{document}\n");

return;
}

void printtexstate (int a [], int b [], int y []) {
    int i;
    int angle;
    printf ("\\documentclass [a4paper]{article}\n");
    printf ("\\usepackage{german}\n");
    printf ("\\usepackage[utf8]{inputenc}\n");
    printf ("\\usepackage{pgf, tikz}\n");
    printf ("\\usetikzlibrary{arrows , automata , positioning}\n\n");

    printf ("\\begin{document}\n");
    printf ("\\begin{tabular}{|c||c|c||c|}");
    printf ("\\hline\n");
    printf ("Zustand & \\multicolumn {2}{||c||}{Folge-Zustand fuer}& Ausgang\\\\\n");
    printf ("\\hline\n");
    printf ("& \\verb\"x=0\" & \\verb\"x=1\" &\\\\\n");
    printf ("\\hline\n");
    printf ("\\hline\n");

    for (i = MIN_STATE;  i < (MAX_STATES + MIN_STATE);  i++) {
        printf ("%i & %i & %i & %i\\\\\n", i, a [i - MIN_STATE], b [i - MIN_STATE], y [i - MIN_STATE]);
        printf ("\\hline\n");
    }
    printf ("\\end{tabular}\n");

    printf ("\\begin{center}\n");
    printf ("\\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=2.5cm]\n");

    printf ("\\node (%i) [state, thick] {%i/%i};\n", MIN_STATE, MIN_STATE, y [MIN_STATE-1]);
    for (i = MIN_STATE+1;  i < (MAX_STATES + MIN_STATE)-1;  i+=2) {
        printf ("\\node (%i) [state, thick, right of= %i] {%i/%i};\n", i, i-1, i, y [i]);
        printf ("\\node (%i) [state, thick, below of= %i] {%i/%i};\n", i+1, i-1, i+1, y [i+1]);
    }
    printf ("\\node (%i) [state, thick, right of= %i] {%i/%i};\n", i, i-1, i, y [i]);

    printf ("\n\n\\path[thick,->]\n");
    for (i = MIN_STATE, angle = 20;  i < (MAX_STATES + MIN_STATE);  i++, angle+=20) {
        printf ("(%i) [bend angle=%i, bend right, above] edge (%i)\n", i, angle, a [i-1]);
        angle += 20;
        printf ("(%i) [bend angle=%i, bend left, below] edge (%i)\n", i, angle, b [i-1]);
    }
    printf (";\n");
    printf ("\\end{tikzpicture}\n");
    printf ("\\end{center}\n");
    printf ("\\end{document}\n");

return;
}



void readcsv (int a [], int b [], int y []) {
    int i;
    int j;
    scanf ("Zustand,FolgeZustandx=0,FolgeZustandx=1,Ausgabe\n");

    for (i = MIN_STATE;  i < (MAX_STATES + MIN_STATE);  i++) {
        scanf ("%i,%i,%i,%i\n", &j, &a [i - MIN_STATE], &b [i - MIN_STATE], &y [i - MIN_STATE]);
        if (j != i) {
            fprintf (stderr, "IO-Error\n");
            exit (1);
        }

    }

return;
}



void createnew (int a [], int b [], int y []) {
    time_t t;
    int i;
    int q [MAX_SPECIAL_STATES];
    int j;

    srand ((int)time (&t));

    q [SPECIAL_STATE_1] = (rand () % MAX_STATES) + MIN_STATE;
    while ((q [SPECIAL_STATE_2] = ((rand () % MAX_SPECIAL_STATES)+MIN_STATE)) == q [SPECIAL_STATE_1]);
    while (((q [SPECIAL_STATE_3] = ((rand () % MAX_STATES)+MIN_STATE)) == q [SPECIAL_STATE_1]) || (q [SPECIAL_STATE_3] == q [SPECIAL_STATE_2]));
    j = rand () % MAX_INPUTS;

    //printf ("Zur Sicherheit: %i %i %i\n", q [SPECIAL_STATE_1], q [SPECIAL_STATE_2], q [SPECIAL_STATE_3]);

    for (i = MIN_STATE;  i < (MAX_STATES+MIN_STATE);  i++) {
        if (i == q [SPECIAL_STATE_1]) {
            a [q [SPECIAL_STATE_1] - MIN_STATE] = q [SPECIAL_STATE_2];
            b [q [SPECIAL_STATE_1] - MIN_STATE] = q [SPECIAL_STATE_3];
            y [q [SPECIAL_STATE_1] - MIN_STATE] = j;
        }
        else if (i == q [SPECIAL_STATE_2]) {
            a [q [SPECIAL_STATE_2] - MIN_STATE] = q [SPECIAL_STATE_3],
            b [q [SPECIAL_STATE_2] - MIN_STATE] = q [SPECIAL_STATE_1];
            y [q [SPECIAL_STATE_2] - MIN_STATE] = j;
        }
        else if (i == q [SPECIAL_STATE_3]) {
            a [q [SPECIAL_STATE_3] - MIN_STATE] = q [SPECIAL_STATE_1];
            b [q [SPECIAL_STATE_3] - MIN_STATE] = q [SPECIAL_STATE_2];
            y [q [SPECIAL_STATE_3] - MIN_STATE] = j;
        }
        else {
             a [i - MIN_STATE] = (rand () % MAX_STATES) + MIN_STATE;
             b [i - MIN_STATE] = (rand () % MAX_STATES) + MIN_STATE;
             y [i - MIN_STATE] = (rand () % MAX_INPUTS);
        }
    }
}

int main (int argc, char *argv []) {
    int a [MAX_STATES];
    int b [MAX_STATES];
    int y [MAX_STATES];

#define CREATE_NEW      0
#define READ_CSV        1
#define PRINT_RAW       0
#define PRINT_TEX       1
#define PRINT_CSV       2
#define PRINT_SOLVE     3
#define PRINT_TEX_STATE 3
#define PRINT_NO_HELP   0
#define PRINT_HELP      1


    int argi;
    int createnew_readcsv = CREATE_NEW;
    int printraw_printtex_print_csv = PRINT_RAW;
    int printhelp = PRINT_NO_HELP;

    for (argi = 1;  argi < argc;  argi++) {
        if ((strcmp ("--create-new", argv [argi]) == 0) || (strcmp ("-n", argv [argi]) == 0))
            createnew_readcsv = CREATE_NEW;
        if ((strcmp ("--read-csv", argv [argi]) == 0) || (strcmp ("-s", argv [argi]) == 0))
            createnew_readcsv = READ_CSV;
        if ((strcmp ("--print-raw", argv [argi]) == 0) || (strcmp ("-r", argv [argi]) == 0))
            printraw_printtex_print_csv = PRINT_RAW;
        if ((strcmp ("--print-csv", argv [argi]) == 0) || (strcmp ("-c", argv [argi]) == 0))
            printraw_printtex_print_csv = PRINT_CSV;
        if ((strcmp ("--print-tex", argv [argi]) == 0) || (strcmp ("-t", argv [argi]) == 0))
            printraw_printtex_print_csv = PRINT_TEX;
        if ((strcmp ("--print-tex-state", argv [argi]) == 0) || (strcmp ("-x", argv [argi]) == 0))
            printraw_printtex_print_csv = PRINT_TEX_STATE;
        if ((strcmp ("--solve", argv [argi]) == 0) || (strcmp ("-l", argv [argi]) == 0))
            printraw_printtex_print_csv = PRINT_SOLVE;
        if ((strcmp ("--help", argv [argi]) == 0) || (strcmp ("-h", argv [argi]) == 0))
            printhelp = PRINT_HELP;
    }
    if (printhelp == PRINT_HELP) {
        printf ("--create-new\n-n\n\n");
        printf ("--read-csv\n-r\n\n");
        printf ("--print-raw\n-s\n\n");
        printf ("--print-csv\n-c\n\n");
        printf ("--print-tex\n-t\n\n");
        printf ("--help\n-h\n\n");
        return 2;
    }
    if (createnew_readcsv == CREATE_NEW)
        createnew (a, b, y);
    else if (createnew_readcsv == READ_CSV)
        readcsv (a, b, y);
    if (printraw_printtex_print_csv == PRINT_RAW)
        printraw (a, b, y);
    else if (printraw_printtex_print_csv == PRINT_TEX)
        printtex (a, b, y);
    else if (printraw_printtex_print_csv == PRINT_CSV)
        printcsv (a, b, y);
    else if (printraw_printtex_print_csv == PRINT_TEX_STATE)
        printtexstate (a, b, y);


    else if (printraw_printtex_print_csv == PRINT_SOLVE);


return 0;
}

zustandsdiagramm

Code: Select all

Zustand		Folge-Zustand fuer	Ausgang
			x=0	x=1				
1			4	3				1
2			2	2				1
3			1	4				1
4			3	1				1
Post Reply