3
* Mikael Lagerkvist <lagerkvist@gecode.org>
6
* Mikael Lagerkvist, 2005
9
* $Date: 2005-07-28 22:52:19 +0200 (Thu, 28 Jul 2005) $ by $Author: schulte $
12
* This file is part of Gecode, the generic constraint
13
* development environment:
14
* http://www.gecode.org
16
* See the file "LICENSE" for information on usage and
17
* redistribution of this file, and for a
18
* DISCLAIMER OF ALL WARRANTIES.
22
namespace Gecode { namespace MiniModel {
26
Matrix<A>::Slice::Slice(Matrix<A>& a,
27
unsigned int fc, unsigned int tc,
28
unsigned int fr, unsigned int tr)
29
: _r((tc-fc)*(tr-fr)), _fc(fc), _tc(tc), _fr(fr), _tr(tr) {
30
if (tc > a.width() || tr > a.height())
31
throw ArgumentOutOfRange("Arguments out of range");
32
if (fc >= tc || fr >= tr)
36
for (unsigned int w = fc; w < tc; ++w) {
37
for (unsigned int h = fr; h < tr; ++h) {
45
Matrix<A>::Slice::operator typename Matrix<A>::args_type(void) {
50
Matrix<A>::Slice::operator Matrix<typename Matrix<A>::args_type>(void) {
51
return Matrix<args_type>(_r, _tc-_fc, _tr-_fr);
57
Matrix<A>::Matrix(A a, unsigned int w, unsigned int h)
58
: _a(a), _w(w), _h(h) {
59
if(_w * _h != static_cast<unsigned int>(_a.size()))
60
throw ArgumentSizeMismatch("Size w*h is not compatible with"
66
Matrix<A>::Matrix(A a, unsigned int n)
67
: _a(a), _w(n), _h(n) {
68
if(n*n != static_cast<unsigned int>(_a.size()))
69
throw ArgumentSizeMismatch("Size n*n are not compatible with"
74
forceinline unsigned int const
75
Matrix<A>::width(void) { return _w; }
77
forceinline unsigned int const
78
Matrix<A>::height(void) { return _h; }
80
forceinline typename Matrix<A>::args_type const
81
Matrix<A>::get_array(void) {
86
forceinline typename Matrix<A>::value_type&
87
Matrix<A>::operator()(unsigned int c, unsigned int r) {
89
throw ArgumentOutOfRange("Arguments out of range");
95
forceinline typename Matrix<A>::Slice
96
Matrix<A>::slice(unsigned int fc, unsigned int tc,
97
unsigned int fr, unsigned int tr) {
98
return Slice(*this, fc, tc, fr, tr);
102
forceinline typename Matrix<A>::args_type
103
Matrix<A>::row(int r) {
104
return slice(0, width(), r, r+1);
108
forceinline typename Matrix<A>::args_type
109
Matrix<A>::col(int c) {
110
return slice(c, c+1, 0, height());
115
// STATISTICS: minimodel-any