File: minrooms.c

package info (click to toggle)
tablix2 0.3.5-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 9,920 kB
  • ctags: 3,351
  • sloc: ansic: 24,593; xml: 13,161; sh: 10,409; makefile: 852; perl: 564; yacc: 289; sed: 16
file content (110 lines) | stat: -rw-r--r-- 3,031 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
/* TABLIX, PGA general timetable solver                                    */
/* Copyright (C) 2002-2006 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: minrooms.c,v 1.2 2006-11-13 11:11:14 avian Exp $ */

/** @module
 *
 * @author Seppe vanden Broucke
 * @author-email
 *
 * @credits Minor modifications by Tomaz Solc
 *
 * @brief 
 * The number of weights added by this module is equal to the total number 
 * of used rooms minus 1.
 * 
 * Of course, you have to use this in combination with the timeplace.so 
 * module, otherwise the best fit would be to place all events in the same 
 * room. Also, this module may not be used as a mandatory one, because a 
 * fitness of zero is unlikely.
 *
 * Finally: I've had best results with small weights, which is also logical.
 *
 * The module is used like all the others, with no other options or directives:
 *
 * <module name="minrooms.so" weight="10" mandatory="no"/>
 *
 * @ingroup Simple meeting scheduling
 */

#include "module.h"

#include <stdlib.h>

static int num_rooms;

int fitness(chromo **c, ext **e, slist **s)
{
	int roomsused[num_rooms];
	int total,a,m,i;

	chromo *room;
	room=c[0];

	total=0;
	// debug("ROOMS: number of rooms: %d", num_rooms);
	for (i=0;i<num_rooms;i++){
		// debug("ROOMS: blanking room %d", i);
		roomsused[i] = 0;
	}
	for(m=0;m<room->gennum;m++) {
		a=room->gen[m];
		// debug("ROOMS: now using room %d", a);
		roomsused[a] = 1;
	}
	for (i=0;i<num_rooms;i++){
		if (roomsused[i] == 1){
			// debug("ROOMS: room %d was used", i);
			total++;
		}else{
			// debug("ROOMS: room %d was not used", i);
		}
	}

	// debug("ROOMS: total %d", total);
	return(total-1);
}

int module_init(moduleoption *opt)
{
	fitnessfunc *f;

	resourcetype *room;
	//resourcetype *time;

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

	num_rooms = room->resnum;
	debug("Available Rooms: %d", num_rooms);

	f=fitness_new("minrooms",
			option_int(opt, "weight"),
			option_int(opt, "mandatory"),
			fitness);

	if(f==NULL) return -1;

	if(fitness_request_chromo(f, "room")) return -1;

	return(0);
}