SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Task.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Copyright (C) 2012 Sergey Lisitsyn
8  */
9 
11 
12 using namespace shogun;
13 
15 {
16  init();
17 
18  m_weight = 0.0;
19  m_name = "task";
20 }
21 
22 CTask::CTask(index_t min_index, index_t max_index,
23  float64_t weight, const char* name) :
24  CSGObject()
25 {
26  init();
27 
28  REQUIRE(min_index<max_index, "min index should be less than max index")
29  m_indices = SGVector<index_t>(max_index-min_index);
30  for (int32_t i=0; i<m_indices.vlen; i++)
31  m_indices[i] = i+min_index;
32  m_weight = weight;
33  m_name = name;
34 }
35 
37  float64_t weight, const char* name) :
38  CSGObject()
39 {
40  init();
41 
42  m_indices = indices;
43 }
44 
45 void CTask::init()
46 {
47  m_subtasks = new CList(true);
49 
50  SG_ADD((CSGObject**)&m_subtasks,"subtasks","subtasks of given task", MS_NOT_AVAILABLE);
51  SG_ADD(&m_indices,"indices","indices of task", MS_NOT_AVAILABLE);
52  SG_ADD(&m_weight,"weight","weight of task", MS_NOT_AVAILABLE);
53 }
54 
56 {
58 }
59 
61 {
62  REQUIRE(m_indices.vlen>1,"Task indices vector must not be empty or contain only one element")
63  bool result = true;
64  for (int32_t i=0; i<m_indices.vlen-1; i++)
65  {
66  if (m_indices[i]!=m_indices[i+1]-1)
67  {
68  result = false;
69  break;
70  }
71  }
72 
73  return result;
74 }
75 
76 void CTask::add_subtask(CTask* subtask)
77 {
78  SGVector<index_t> subtask_indices = subtask->get_indices();
79  for (int32_t i=0; i<subtask_indices.vlen; i++)
80  {
81  bool found = false;
82  for (int32_t j=0; j<m_indices.vlen; j++)
83  {
84  if (subtask_indices[i] == m_indices[j])
85  {
86  found = true;
87  break;
88  }
89  }
90  if (!found)
91  SG_ERROR("Subtask contains indices that are not contained in this task\n")
92  }
93  m_subtasks->append_element(subtask);
94 }
95 
97 {
99  return m_subtasks;
100 }
101 
103 {
104  return m_subtasks->get_num_elements();
105 }

SHOGUN Machine Learning Toolbox - Documentation