File: placecapability.c

package info (click to toggle)
tablix2 0.3.5-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,024 kB
  • sloc: ansic: 24,593; xml: 13,161; sh: 10,409; makefile: 800; perl: 564; yacc: 289; sed: 16
file content (166 lines) | stat: -rw-r--r-- 4,158 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* TABLIX, PGA general timetable solver                              */
/* Copyright (C) 2002 Tomaz Solc                                           */

/* This program is free software; you can redistribute it and/or modify    */
/* it under the terms of the GNU General Public License as published by    */
/* the Free Software Foundation; either version 2 of the License, or       */
/* (at your option) any later version.                                     */

/* This program is distributed in the hope that it will be useful,         */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of          */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
/* GNU General Public License for more details.                            */

/* You should have received a copy of the GNU General Public License       */
/* along with this program; if not, write to the Free Software             */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

/* $Id: placecapability.c,v 1.9 2006-08-29 14:32:24 avian Exp $ */

/** @module
 *
 * @author Tomaz Solc 
 * @author-email tomaz.solc@tablix.org
 *
 * @brief Use this module if you want to schedule certain events only in 
 * classrooms that have the neccessary capabilities.
 *
 * This module does not use a fitness function. This means that the "mandatory"
 * and "weight" options are ignored. This restriction is always mandatory.
 *
 * See "preferredroom.so" module if you need a non-mandatory restriction of
 * a similar type.
 *
 * @ingroup School scheduling, Multiweek scheduling
 */

/** @resource-restriction capability
 *
 * <resource name="special-classroom">
 *	<restriction type="capability">special-capability</restriction>
 * </resource>
 *
 * Use this restriction to specify which capabilities does a certain classroom
 * have. You can have more than one capability per classroom.
 *
 * A classroom has no capabilities by default.
 */

/** @tuple-restriction capability
 *
 * <event name="special-event" repeats="1">
 * 	<restriction type="capability">special-capability</restriction>
 * </event>
 *
 * Use this restriction to specify that the current event can only be scheduled
 * in rooms with the specified capability. 
 *
 * You can use more than one restriction per event. This means that this event
 * can only be scheduled in rooms that have all of the specified capabilities.
 *
 * An event can be scheduled in any room by default.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

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

#include "module.h"

/* maximum number of capabilities a single room can have */
#define MAX_CAP 25

/* list of capabilites for a classroom */
struct capability {
        char **cap;    
        int capnum;
};

static struct capability *caps;

static int roomid;

int cap_list(int *val, char *cap)
{
	int resid;
	int c;
	int num;

	num=0;
	for(resid=0;resid<dat_restype[roomid].resnum;resid++) {
		for(c=0;c<caps[resid].capnum;c++) {
			if (!strcmp(caps[resid].cap[c], cap)) {
				val[num]=resid;
				num++;
				break;
			}
		}
	}

	return(num);
}

int getcapability(char *restriction, char *cont, resource *res)
{
	int resid;
	struct capability *cap;

	resid=res->resid;
	assert(resid>=0);

	cap=&caps[resid];

	cap->cap[cap->capnum]=strdup(cont);
	cap->capnum++;

	return 0;
}

int getrestriction(char *restriction, char *cont, tupleinfo *tuple)
{
	int *val;
	int valnum;

	val=malloc(sizeof(*val)*dat_restype[roomid].resnum);

	valnum=cap_list(val, cont);

	domain_and(tuple->dom[roomid], val, valnum);

	free(val);

	return 0;
}

int module_init(moduleoption *opt)
{
	resourcetype *room;
	int c;

	room=restype_find("room");
	if(room==NULL) {
		error(_("Resource type %s not found"), "room");
		return(-1);
	}
	roomid=room->typeid;

	caps=malloc(sizeof(*caps)*room->resnum);
	if(caps==NULL) {
		error(_("Can't allocate memory"));
		return(-1);
	}

	for(c=0;c<room->resnum;c++) {
		caps[c].cap=malloc(sizeof(*caps[c].cap)*MAX_CAP);
		caps[c].capnum=0;
	}

	handler_res_new("room", "capability", getcapability);
	handler_tup_new("capability", getrestriction);

	return 0;
}